+ Reply to Thread
Results 1 to 3 of 3

Running a macro for all visible worksheets in a workbook

  1. #1
    Registered User
    Join Date
    04-08-2005
    Posts
    12

    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

  2. #2
    Bob Phillips
    Guest

    Re: Running a macro for all visible worksheets in a workbook

    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"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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. #3
    Registered User
    Join Date
    04-08-2005
    Posts
    12
    Thanks for that. I'd tweaked my code a little in the meantime but the xlsheetvisible code was the key I needed.

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1