Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 6th, 2003, 03:21 AM
james_skeggs james_skeggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 11 james_skeggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Complex Looping Function

Hi,

I am looking to run the following macro, but i want to be able to say for Sheets("P0150*") where * is UM, UP, UI etc, and then the whole lot to run without me having to paste the same thing over and over again...

Sheets("P0150UM").Select
Sheets.Add
Sheets("Sheet1").Name = "UM Sold"
Sheets("P0150UM").Name = "UM Bought"
Sheets("UM Bought").Select

Range("A1").Select
Call CountRow1

Dim range1 As String
range1 = "A" & a + 2
Range(range1).Select
Call CountRow2


Dim Range2 As String
Range2 = "V" & a + 2 + b
Range(range1, Range2).Select
Selection.Cut
Sheets("UM Sold").Select
Range("A1").Select
ActiveSheet.Paste

Please can someone give me some help writing a loop to do this function?

Many thanks in advance
James

Reply With Quote
  #2  
Old August 6th, 2003, 07:55 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Code:
Dim sSheetName(number of sheets you have) As String
Dim lCntr As Long
Dim lMaxElements as Long

sSheetName(0) = "UM"
sSheetName(1) = "UP"
sSheetName(2) = "UI"
'continue for all sheets

lMaxElements = number of sheets you have starting from 0
For lCntr = 0 to lMaxElements
    Sheets("P0150" & sSheetName(lCntr)).Select
    Sheets.Add
    Sheets("Sheet1").Name = sSheetName & " Sold"
    Sheets("P0150" & sSheetName(lCntr)).Name = sSheetName(lCntr) & " Bought"
    Sheets(sSheetName(lCntr) & "Bought").Select

    Range("A1").Select
    Call CountRow1

    Dim range1 As String
    range1 = "A" & a + 2
    Range(range1).Select
    Call CountRow2

    Dim Range2 As String
    Range2 = "V" & a + 2 + b
    Range(range1, Range2).Select
    Selection.Cut
    Sheets(sSheetName(lCntr) & " Sold").Select
    Range("A1").Select
    ActiveSheet.Paste 
Next lCntr

Something like this would probably work.

Reply With Quote
  #3  
Old August 6th, 2003, 11:42 AM
james_skeggs james_skeggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 11 james_skeggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Complex Looping Function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway