PC Review


Reply
Thread Tools Rate Thread

do something for each sheet

 
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      5th Sep 2007
hey all,
i found this snippet on the net but it doesn't seem to be working for me:

Sub proTest()
Dim varSheet As Variant

For Each varSheet In Worksheets
Range("A1").Value = 22
Next

End Sub

It only puts it into the current active sheet. can someone please tell me
how to run it for each sheet or what i'm doing wrong in the preceding snippet?

thanks,
rodchar
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      5th Sep 2007
You need to qualify the Range object with varSheet and it's also better to
declare varsheet as a worksheet object rather than variant. like this:

Sub proTest()
Dim varSheet As Worksheet

For Each varSheet In Worksheets
varSheet.Range("A1").Value = 22
Next

End Sub



--
Hope that helps.

Vergel Adriano


"rodchar" wrote:

> hey all,
> i found this snippet on the net but it doesn't seem to be working for me:
>
> Sub proTest()
> Dim varSheet As Variant
>
> For Each varSheet In Worksheets
> Range("A1").Value = 22
> Next
>
> End Sub
>
> It only puts it into the current active sheet. can someone please tell me
> how to run it for each sheet or what i'm doing wrong in the preceding snippet?
>
> thanks,
> rodchar

 
Reply With Quote
 
=?Utf-8?B?cm9kY2hhcg==?=
Guest
Posts: n/a
 
      5th Sep 2007
thank you, that worked.

"Vergel Adriano" wrote:

> You need to qualify the Range object with varSheet and it's also better to
> declare varsheet as a worksheet object rather than variant. like this:
>
> Sub proTest()
> Dim varSheet As Worksheet
>
> For Each varSheet In Worksheets
> varSheet.Range("A1").Value = 22
> Next
>
> End Sub
>
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "rodchar" wrote:
>
> > hey all,
> > i found this snippet on the net but it doesn't seem to be working for me:
> >
> > Sub proTest()
> > Dim varSheet As Variant
> >
> > For Each varSheet In Worksheets
> > Range("A1").Value = 22
> > Next
> >
> > End Sub
> >
> > It only puts it into the current active sheet. can someone please tell me
> > how to run it for each sheet or what i'm doing wrong in the preceding snippet?
> >
> > thanks,
> > rodchar

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel sheet bootom half sheet goes behind top part of sheet rob Microsoft Excel Worksheet Functions 2 17th Jan 2009 01:28 AM
Duplicate sheet, autonumber sheet, record data on another sheet des-sa Microsoft Excel Worksheet Functions 0 8th May 2008 06:56 PM
How do I select price from sheet.b where sheet.a part no = sheet.b =?Utf-8?B?U29ubnk=?= Microsoft Excel Worksheet Functions 4 4th Apr 2006 05:08 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. =?Utf-8?B?Um9uTWM1?= Microsoft Excel Misc 9 3rd Feb 2005 12:51 AM
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B Hannes Heckner Microsoft Excel Programming 1 5th Mar 2004 09:10 AM


Features
 

Advertising
 

Newsgroups
 


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