ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through worksheets (https://www.excelbanter.com/excel-programming/382475-looping-through-worksheets.html)

RominallL

Looping through worksheets
 
What's the easiest way to loop through worksheets?

I can't use Sheet(1) reference because the sheet numbers will change, I'll
have to use the actual name.

I'll need to do some formatting on each sheet.

Ron de Bruin

Looping through worksheets
 
Hi RominallL

Try this

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Range("A1").Interior.ColorIndex = 3
Next sh


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"RominallL" wrote in message ...
What's the easiest way to loop through worksheets?

I can't use Sheet(1) reference because the sheet numbers will change, I'll
have to use the actual name.

I'll need to do some formatting on each sheet.


Gary''s Student

Looping through worksheets
 
Sub marine()
For Each w In Worksheets
w.Activate
Range("A1").Interior.ColorIndex = 6
Next
End Sub

--
Gary's Student
gsnu200703


"RominallL" wrote:

What's the easiest way to loop through worksheets?

I can't use Sheet(1) reference because the sheet numbers will change, I'll
have to use the actual name.

I'll need to do some formatting on each sheet.


RominallL

Looping through worksheets
 
Ooops, forgot to mention that there are 3 sheets that won't get the
formatting. And those names will not change.

"Ron de Bruin" wrote:

Hi RominallL

Try this

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Range("A1").Interior.ColorIndex = 3
Next sh


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"RominallL" wrote in message ...
What's the easiest way to loop through worksheets?

I can't use Sheet(1) reference because the sheet numbers will change, I'll
have to use the actual name.

I'll need to do some formatting on each sheet.



Ron de Bruin

Looping through worksheets
 
Try this

Change a, b, c to your sheet names

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "a" And sh.Name < "b" And sh.Name < "c" Then
sh.Range("A1").Interior.ColorIndex = 3
End If
Next sh


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"RominallL" wrote in message ...
Ooops, forgot to mention that there are 3 sheets that won't get the
formatting. And those names will not change.

"Ron de Bruin" wrote:

Hi RominallL

Try this

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Range("A1").Interior.ColorIndex = 3
Next sh


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"RominallL" wrote in message ...
What's the easiest way to loop through worksheets?

I can't use Sheet(1) reference because the sheet numbers will change, I'll
have to use the actual name.

I'll need to do some formatting on each sheet.




All times are GMT +1. The time now is 11:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com