Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping through Sheets
I am not 100% sure exactly what you are looking for but if all you want to do
is loop through all of the sheets in a workbook this will do it... dim wks as worksheet for each wks in worksheets 'do that voodoo that you do next wks "Utkarsh Majmudar" wrote: I have a Sub that I run on each of the Sheets in my workbook. This Sub essentially copies data from a set of files into each sheet of my main file. Is there a way in which I need not run the macro 'n' number of times but loop through all the sheets at one go. My current code looks like this: *************** Sub Populate() Dim Sname As String Dim IFname As String Application.ScreenUpdating = False myfile = ActiveWorkbook.Name mypath = ActiveWorkbook.Path Range("E11").Value = ActiveSheet.Name Sname = Range("E11").Value IFname = Sname & ".xls" Workbooks.Open Filename:=mypath & "\" & IFname 'Enter Basic Information Workbooks(IFname).Sheets(Sname).Activate Range("E1").Select Selection.Copy Windows(myfile).Activate Range("E1").Select ActiveSheet.Paste ...... more stuff here Workbooks(IFname).Sheets(Sname).Activate ActiveWorkbook.Close savechanges:=False Workbooks(myfile).Sheets(Sname).Activate Range("A1").Select Application.ScreenUpdating = True End Sub ***************** Thanks for the help! Utkarsh |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping through Sheets
Jim
Your idea is right. Unfortunately the code doesn't run. It populates the first sheet but does not move on to the next one. Any clues? Utkarsh *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping through Sheets
Can you paste your revised code. We should be able to figure out what' wrong. Hard to tell without the code -- CBrin ----------------------------------------------------------------------- CBrine's Profile: http://www.excelforum.com/member.php...fo&userid=1470 View this thread: http://www.excelforum.com/showthread.php?threadid=26324 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping through Sheets
Thanks to all those who helped. Resolved the problem with the following
code that I found on a posting: **************** Dim sh As Worksheet For i = 1 To Sheets.Count Set sh = Sheets(i) sh.Activate 'My voodoo stuff here Next i ***************** Utkarsh *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Looping between sheets picking up values on the way | Excel Worksheet Functions | |||
Looping through Sheets | Excel Programming | |||
looping every third row | Excel Programming | |||
Looping through Sheets and passing values to an Array | Excel Programming | |||
Looping through sheets | Excel Programming |