+ Reply to Thread
Results 1 to 2 of 2

Sheet names in VBA scripts

Hybrid View

  1. #1
    Registered User
    Join Date
    01-01-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    26

    Sheet names in VBA scripts

    Hoping someone can help me.

    I have the following code that relates to sheet names Sheet 1 - 20 in a workbook. However, in a new workbook, I have the sheet names as "ABC (1)", "ABC (2)" etc to 20. Can anyone kindly change the code below to reflect to the names of the sheets such as "ABC (1)" rather than "Sheet1".

    Hope this makes sense.

    Many thanks,

    Nick

    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim i&
        
        If Intersect(Target, Range("C3:C4")) Is Nothing Then Exit Sub
        
        For i = 1 To 20     'enable in sheets marked "1"
            Worksheets("Sheet1").EnableCalculation = True
            Worksheets("Sheet" & i).EnableCalculation = False
        Next i
    
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,173

    Re: Sheet names in VBA scripts

    Maybe:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i&
    
    If Intersect(Target, Range("C3:C4")) Is Nothing Then Exit Sub
    
    For i = 1 To 20     'enable in sheets marked "1"
        Worksheets("ABC (1)").EnableCalculation = True
        Worksheets("ABC (" & i & ")").EnableCalculation = False
    Next i
    
    End Sub

    or even:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i&
    
    If Intersect(Target, Range("C3:C4")) Is Nothing Then Exit Sub
    
    Worksheets("ABC (1)").EnableCalculation = True
    For i = 2 To 20     'enable in sheets marked "1"
        Worksheets("ABC (" & i & ")").EnableCalculation = False
    Next i
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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