Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Simple looping question

Hi everyone,

I have about 20 different worksheets in the same workbook. I also have
a main macro for the workbook. I know how to loop the macro through
all the worksheets. However how do I loop the sheets I want only?

i.e. Loop sheets("A"), sheets("B") and Sheets("Z") only, Not running
particular part of marco for other sheets.


Thanks for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Simple looping question

dim arr,x
arr=Array("A","B","D","X")

for x=lbound(arr) to ubound(arr)

with thisworkbook.sheets(arr(x))
'do stuff
end with

next x


Tim



"James8309" wrote in message
...
Hi everyone,

I have about 20 different worksheets in the same workbook. I also have
a main macro for the workbook. I know how to loop the macro through
all the worksheets. However how do I loop the sheets I want only?

i.e. Loop sheets("A"), sheets("B") and Sheets("Z") only, Not running
particular part of marco for other sheets.


Thanks for your help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Simple looping question

On Jun 12, 4:25*pm, "Tim Williams" <timjwilliams at gmail dot com
wrote:
dim arr,x
arr=Array("A","B","D","X")

for x=lbound(arr) to ubound(arr)

* * with thisworkbook.sheets(arr(x))
* * * * 'do stuff
* * end with

next x

Tim

"James8309" wrote in message

...



Hi everyone,


I have about 20 different worksheets in the same workbook. I also have
a main macro for the workbook. I know how to loop the macro through
all the worksheets. However how do I loop the sheets I want only?


i.e. Loop sheets("A"), sheets("B") and Sheets("Z") only, Not running
particular part of marco for other sheets.


Thanks for your help- Hide quoted text -


- Show quoted text -



In the middle of my code, I have this part where it does sumif.
Currently It only does it for one sheet. I just want to specify sheets
that will perform the code below (e.g. Sheet"A" and Sheet"B"). I tried
the code above but seems like it is not working.


Dim CELL As Range
Dim LR As Integer
Dim MYPATH As String
Dim WB As Workbook
Dim FNAME As String
Dim SUMREF As String
Dim COLCOUNT As Long

MYPATH = "C:\My Documents\"
LR = Range("A" & Rows.Count).End(xlUp).Row
Set ThisSht = Workbooks("Macro for Report.xls").ActiveSheet

'column B = 2

For i = 2 To 41
COLCOUNT = i
With ThisSht
FNAME = MYPATH & .Range("A1").Value & "\" & _
Year(.Cells(5, COLCOUNT).Value) & "\" & _
Format(.Cells(5, COLCOUNT).Value, "MMM YY")
Debug.Print FNAME
FNAME = FNAME & ".XLS"
Set WB = Workbooks.Open(Filename:=FNAME)
Debug.Print FNAME

For Each CELL In .Range(.Cells(6, COLCOUNT), .Cells(LR, COLCOUNT))
SUMREF = .Range("A" & CELL.Row).Value
CELL.Interior.ColorIndex = 33
CELL.Value = Application.WorksheetFunction. _
SumIf(WB.Sheets("Sheet1").Range("H:U"), _
SUMREF, WB.Sheets("Sheet1").Range("U:U"))
Next CELL
WB.Close
COLCOUNT = COLCOUNT + 1
End With
Next
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple looping question Person Excel Programming 3 December 1st 06 12:11 AM
Help with simple looping program Stephen Excel Programming 2 August 4th 06 06:55 PM
Simple looping question light Excel Programming 2 August 19th 05 09:28 PM
Simple looping question light Excel Programming 2 August 16th 05 06:30 PM
Simple Array Looping Nikky Excel Programming 2 April 20th 05 10:38 PM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"