Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Looping through Worksheets | Excel Programming | |||
looping through worksheets from addin | Excel Programming | |||
looping through worksheets from addin | Excel Programming | |||
looping through worksheets | Excel Programming | |||
looping through worksheets | Excel Programming |