Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Craig_Richards
 
Posts: n/a
Default Running a macro for all visible worksheets in a workbook


Hello,

I'm not the most experienced of macro writers but can normally muddle
through inelegantly enough. However this one has got me stuck. Can
anyone help?

I am trying to run a macro for all visible worksheets in a workbook and
failing gallantly. This is my code:

Sub update()

application.ScreenUpdating = False
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = "End" Then GoTo finish
sht.Select
Range("A1").Select
RC = EssMenuVRetrieve()

Next sht
finish:
application.ScreenUpdating = True
End Sub

It updates the visible sheets fine but then I get run time error 1004
saying that Method 'select of object'_worksheet failed

Any ideas? I think I have probably not defined the final sheet
correctly but I thought it worked that way.

I appreaciate any feedback you could hive me.

Thanks


--
Craig_Richards
------------------------------------------------------------------------
Craig_Richards's Profile: http://www.excelforum.com/member.php...o&userid=21936
View this thread: http://www.excelforum.com/showthread...hreadid=393813

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Does this do it?

Sub update()
Application.ScreenUpdating = False
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible = xlSheetVisible Then
If sht.Name < "End" Then
sht.Select
Range("A1").Select
RC = EssMenuVRetrieve()
End If
End If
Next sht
finish:
Application.ScreenUpdating = True
End Sub

--
HTH

Bob Phillips

"Craig_Richards"
<Craig_Richards.1tfx2h_1123495512.3228@excelforu m-nospam.com wrote in
message news:Craig_Richards.1tfx2h_1123495512.3228@excelfo rum-nospam.com...

Hello,

I'm not the most experienced of macro writers but can normally muddle
through inelegantly enough. However this one has got me stuck. Can
anyone help?

I am trying to run a macro for all visible worksheets in a workbook and
failing gallantly. This is my code:

Sub update()

application.ScreenUpdating = False
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = "End" Then GoTo finish
sht.Select
Range("A1").Select
RC = EssMenuVRetrieve()

Next sht
finish:
application.ScreenUpdating = True
End Sub

It updates the visible sheets fine but then I get run time error 1004
saying that Method 'select of object'_worksheet failed

Any ideas? I think I have probably not defined the final sheet
correctly but I thought it worked that way.

I appreaciate any feedback you could hive me.

Thanks


--
Craig_Richards
------------------------------------------------------------------------
Craig_Richards's Profile:

http://www.excelforum.com/member.php...o&userid=21936
View this thread: http://www.excelforum.com/showthread...hreadid=393813



  #3   Report Post  
Craig_Richards
 
Posts: n/a
Default


Thanks for that. I'd tweaked my code a little in the meantime but the
xlsheetvisible code was the key I needed.

Cheers


--
Craig_Richards
------------------------------------------------------------------------
Craig_Richards's Profile: http://www.excelforum.com/member.php...o&userid=21936
View this thread: http://www.excelforum.com/showthread...hreadid=393813

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
Prevent A Macro From Running If SpreadSheet is Filtered carl Excel Worksheet Functions 1 June 22nd 05 04:04 PM
automatically running a macro 42410 Excel Discussion (Misc queries) 2 April 26th 05 03:10 PM
How to stop getting the file save box when running a macro Pank Mehta Excel Discussion (Misc queries) 1 March 29th 05 04:05 PM
CREATE MACRO TO COPY MULTIPLE WORKSHEETS Bewilderd jim Excel Discussion (Misc queries) 5 March 3rd 05 10:00 PM
Shadows of the Pivottable Field List while macro is running David P Excel Worksheet Functions 0 February 25th 05 07:11 PM


All times are GMT +1. The time now is 05:14 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"