Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop Through worksheets

Hi All,

I need a VBA code for looping through all the worksheets and add th
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephe

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop Through worksheets

Dim sh as Worksheet
for each sh in Activeworkbook.Worksheets
if lcase(sh.name) < "overview" then
sh.range("A1").Formula = "=Today()"
' or for a hard coded date
' sh.Range("A1").Value = Date
sh.range("A1").NumberFormat = "mm/dd/yyyy"
end if
Next

--
Regards,
Tom Ogilvy

"Stephen " wrote in message
...
Hi All,

I need a VBA code for looping through all the worksheets and add the
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephen


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Loop Through worksheets

Stephen, give this a try.

Troy

Sub AddToday()
Dim ii As Integer

For ii = 1 To Worksheets.Count
If Worksheets(ii).Name < "Overview" Then
Worksheets(ii).Range("A1").Formula = "=today()"
End If
Next ii
End Sub


"Stephen " wrote in message
...
Hi All,

I need a VBA code for looping through all the worksheets and add the
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephen


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop Through worksheets

Thank you all. The code works great!!

Stephen

TroyW wrote:
*Stephen, give this a try.

Troy

Sub AddToday()
Dim ii As Integer

For ii = 1 To Worksheets.Count
If Worksheets(ii).Name < "Overview" Then
Worksheets(ii).Range("A1").Formula = "=today()"
End If
Next ii
End Sub


"Stephen " wrote in message
...
Hi All,

I need a VBA code for looping through all the worksheets and ad

the
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephen


---
Message posted from http://www.ExcelForum.com/


--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Loop Through worksheets

The 2 replies to the original question brings up a couple of points
about VBA programming I do not understand, hope someone can enlighten
me.
1. Why dim a variable (in this case "sh") to replace Worksheets? Why not
just work directly with the built in value as the second response does?
2. Once having "Dim sh as Worksheet" why is it that the statement "for
each sh in Activeworkbook.Worksheets" automatically assigns sh all of
the worksheets since sh has been defined as only a (one) worksheet?
Thanks

"Stephen <" wrote:

Hi All,

I need a VBA code for looping through all the worksheets and add the
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephen

---
Message posted from http://www.ExcelForum.com/




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Loop Through worksheets

Hi
both ways are possible but Tom's solution using a
worksheet object has the following benefits (IMHO)
- easier to write using an object reference
- you could use this reference to store the old object and
use it later in your code

Also using a for ... each construct is possible. This
statement will loop through all worksheets in the
collection 'worksheets' and assigns the current loop value
to this object variable


-----Original Message-----
The 2 replies to the original question brings up a couple

of points
about VBA programming I do not understand, hope someone

can enlighten
me.
1. Why dim a variable (in this case "sh") to replace

Worksheets? Why not
just work directly with the built in value as the second

response does?
2. Once having "Dim sh as Worksheet" why is it that the

statement "for
each sh in Activeworkbook.Worksheets" automatically

assigns sh all of
the worksheets since sh has been defined as only a (one)

worksheet?
Thanks

"Stephen <" wrote:

Hi All,

I need a VBA code for looping through all the

worksheets and add the
=today() is cell A1, except in sheet "Overview".

Please help:)

Stephen

---
Message posted from http://www.ExcelForum.com/


.

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
Loop worksheets merry_fay Excel Discussion (Misc queries) 2 January 7th 09 01:54 PM
Loop worksheets Steve[_35_] Excel Programming 3 November 25th 03 04:46 AM
Loop thru files in DIR, delete worksheets & reset worksheet Name property?? Mike Taylor Excel Programming 1 October 24th 03 04:14 AM
Renaming Worksheets with For Each Loop [email protected] Excel Programming 3 October 23rd 03 09:47 PM
Conditional Lookup and copy loop between worksheets David S[_3_] Excel Programming 1 September 30th 03 02:10 AM


All times are GMT +1. The time now is 03:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"