Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
sa02000
 
Posts: n/a
Default Same action in different worksheets


I am trying to do same action in all the sheets of an open workbook. I
started with simple code below but it does not work. I get an error
"type mismatch" at
For Each sht In Worksheets


Sub tryabc()

Dim sht As Worksheets
For Each sht In Worksheets

Range("I1").Select
ActiveCell.FormulaR1C1 = "Status"

Next sht

End Sub

Thanks
Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119

  #2   Report Post  
sa02000
 
Posts: n/a
Default


Well I figured out part of the problem and atleast now it does not give
me an error but now it only works for one worksheet and does not do
same action on all worksheets I have in the workbook.
Here is the code...

Help Please!!


Sub tryabc()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
Range("I1").Select
Next sh
End Sub


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119

  #3   Report Post  
Earl Kiosterud
 
Posts: n/a
Default

Jay,

I think it's a typo. You dimmed sht as Worksheets, which is a collection.
Dim sht as Worksheet
--
Earl Kiosterud
www.smokeylake.com

"sa02000" wrote in
message ...

I am trying to do same action in all the sheets of an open workbook. I
started with simple code below but it does not work. I get an error
"type mismatch" at
For Each sht In Worksheets


Sub tryabc()

Dim sht As Worksheets
For Each sht In Worksheets

Range("I1").Select
ActiveCell.FormulaR1C1 = "Status"

Next sht

End Sub

Thanks
Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile:
http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119



  #4   Report Post  
Earl Kiosterud
 
Posts: n/a
Default

Jay,

Then it occurs to me that ActiveCell will not be the sht worksheet you're
looping through, since you haven't selected it. Better yet, do it directly
(without bothering to select the sheet):

sht.Range("I1").Value = "Status"
--
Earl Kiosterud
www.smokeylake.com

"sa02000" wrote in
message ...

I am trying to do same action in all the sheets of an open workbook. I
started with simple code below but it does not work. I get an error
"type mismatch" at
For Each sht In Worksheets


Sub tryabc()

Dim sht As Worksheets
For Each sht In Worksheets

Range("I1").Select
ActiveCell.FormulaR1C1 = "Status"

Next sht

End Sub

Thanks
Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile:
http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119



  #5   Report Post  
sa02000
 
Posts: n/a
Default


Yeah I changed
Dim sht as worksheets to

Dim sht as worksheet

Now atleast I don't get the error but still it does not perform the
following actions on all the worksheets. here is the code that i am
working with. Please help!!

Sub tryabc()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
Range("I1").Select
ActiveCell.FormulaR1C1 = "Status"
Next sh
End Sub

Thanks,
Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119



  #6   Report Post  
sa02000
 
Posts: n/a
Default


Well I think I figured it out. I had to add
sh.activate
before Range("I1").Select line

Thank you Eric. The reason I did not want to do it direct (as you
suggested) was because I know very soon I will want to do lot of same
actions on all worksheets.


Sub tryabc()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.activate
Range("I1").Select
ActiveCell.FormulaR1C1 = "Status"
Next sh
End Sub

Thanks again. This forum ROCKS!!

Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=475119

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
Print order of worksheets Stray Doug Excel Discussion (Misc queries) 3 September 21st 05 12:37 AM
Changing a Link Mid-way Across Worksheets Frosty Excel Worksheet Functions 0 August 25th 05 12:03 AM
Excel needs to have the ability to insert "SUB" worksheets KFEagle Excel Worksheet Functions 2 July 27th 05 08:13 PM
Adding multiple worksheets Craig Excel Worksheet Functions 1 July 6th 05 07:21 PM
HELP! How do you--> Lock a set of rows but also link worksheets to FRUSTRATED Excel Discussion (Misc queries) 6 December 29th 04 10:05 PM


All times are GMT +1. The time now is 01:22 AM.

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"