Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
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
Looping between sheets picking up values on the way bungie Excel Worksheet Functions 3 March 5th 06 07:22 AM
Looping through Sheets dalejrstwin Excel Programming 0 September 24th 04 06:43 PM
looping every third row Jason Hancock Excel Programming 5 July 1st 04 08:00 PM
Looping through Sheets and passing values to an Array Michael Rhein Excel Programming 2 February 13th 04 10:54 AM
Looping through sheets Eric[_7_] Excel Programming 1 July 24th 03 04:45 PM


All times are GMT +1. The time now is 01:44 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"