Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Looping through Worksheets

Can someone lend some code that will allow me to open each worksheet in my
workbook through code, make a change to the worksheet and move to the next
until all worksheets have been updated. Then let me know the upate has been
done to all worksheets in the workbook.

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Looping through Worksheets

Hi Steve,

Sub Loop_sheets()
Dim sh as worksheet

For each sh in activeworkbook.worksheets
'
'
'
Next sh

End sub

Thanks a lot,
Hari
India

"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in my
workbook through code, make a change to the worksheet and move to the next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Looping through Worksheets

Hi Steve,

Try something like:

Sub Tester()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets

'Do your stuff, e.g.:
Range("A1").Interior.ColorIndex = 3
Next sh
MsgBox "Done!"
End Sub


---
Regards,
Norman



"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in my
workbook through code, make a change to the worksheet and move to the next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Looping through Worksheets

Hi Steve,

Range("A1").Interior.ColorIndex = 3


Should be:

sh. Range("A1").Interior.ColorIndex = 3


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Steve,

Try something like:

Sub Tester()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets

'Do your stuff, e.g.:
Range("A1").Interior.ColorIndex = 3
Next sh
MsgBox "Done!"
End Sub


---
Regards,
Norman



"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in
my
workbook through code, make a change to the worksheet and move to the
next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Looping through Worksheets

If I am trying to place something in cell a1 using this code, I only get the
results on the active workbook.. What am I doing wrong?
Thanks,


"Hari Prasadh" wrote:

Hi Steve,

Sub Loop_sheets()
Dim sh as worksheet

For each sh in activeworkbook.worksheets
'
'
'
Next sh

End sub

Thanks a lot,
Hari
India

"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in my
workbook through code, make a change to the worksheet and move to the next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Looping through Worksheets

You're not doing anything wrong -
The code is set to work on the ActiveWorkbook!

In your code you can either select different workbooks,
or you can specify which workbook:

Workbooks("MyWorkbook.xls").Activate

or cycle through all open workbooks.

--
steveB

Remove "AYN" from email to respond
"Steve" wrote in message
...
If I am trying to place something in cell a1 using this code, I only get
the
results on the active workbook.. What am I doing wrong?
Thanks,


"Hari Prasadh" wrote:

Hi Steve,

Sub Loop_sheets()
Dim sh as worksheet

For each sh in activeworkbook.worksheets
'
'
'
Next sh

End sub

Thanks a lot,
Hari
India

"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in
my
workbook through code, make a change to the worksheet and move to the
next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Looping through Worksheets

You need to reference your range with the sheet object that is moving
throught the worksheets collection. So something like this...

Sub Loop_sheets()
Dim sh as worksheet

For each sh in activeworkbook.worksheets
sh.range("A1").value = "Tada"
'
Next sh

End sub


--
HTH...

Jim Thomlinson


"Steve" wrote:

If I am trying to place something in cell a1 using this code, I only get the
results on the active workbook.. What am I doing wrong?
Thanks,


"Hari Prasadh" wrote:

Hi Steve,

Sub Loop_sheets()
Dim sh as worksheet

For each sh in activeworkbook.worksheets
'
'
'
Next sh

End sub

Thanks a lot,
Hari
India

"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in my
workbook through code, make a change to the worksheet and move to the next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Looping through Worksheets

I think I got it! Thanks so much everyone for your help.

Greatly appreciated.

"Norman Jones" wrote:

Hi Steve,

Range("A1").Interior.ColorIndex = 3


Should be:

sh. Range("A1").Interior.ColorIndex = 3


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Steve,

Try something like:

Sub Tester()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets

'Do your stuff, e.g.:
Range("A1").Interior.ColorIndex = 3
Next sh
MsgBox "Done!"
End Sub


---
Regards,
Norman



"Steve" wrote in message
...
Can someone lend some code that will allow me to open each worksheet in
my
workbook through code, make a change to the worksheet and move to the
next
until all worksheets have been updated. Then let me know the upate has
been
done to all worksheets in the workbook.

Thanks,






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 through Worksheets Kirk P. Excel Programming 1 February 7th 05 05:14 PM
looping through worksheets from addin jason Excel Programming 1 October 9th 03 01:09 PM
looping through worksheets from addin BrianB Excel Programming 0 October 9th 03 09:05 AM
looping through worksheets Alex ekster Excel Programming 1 July 21st 03 03:16 AM
looping through worksheets alex Excel Programming 0 July 20th 03 06:43 PM


All times are GMT +1. The time now is 10:13 PM.

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"