+ Reply to Thread
Results 1 to 3 of 3

Call sheet name but sheet name may vary.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Call sheet name but sheet name may vary.

    I have a report done for me but the sheet names flip flop between "Migrated" or "Sheet 1" and "Non-Migrated" or "Sheet 2". So my macro breaks.

    How do I set worksheet to have either name. I don't know if I have to do an array and if I do, how to use that other than just declaring the array.

    Sub ED4NotepadFormat()
    
    'On Error Resume Next
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Dim sht As Worksheet
    Dim objListObj As ListObject
    
    'Migrated - Sheet 1
    Set sht = ActiveWorkbook.Worksheets("Non-Migrated") '''or sheet 1
    
    'Non-Migrated - Sheet 2
    Set wrksht = ActiveWorkbook.Worksheets("Migrated") '''or sheet 2
    Dim lastrow As String
    Dim ws As Worksheet

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,746

    Re: Call sheet name but sheet name may vary.

    One option is
       If Evaluate("isref('Non-migrated'!A1)") Then
          Set sht = ActiveWorkbook.Worksheets("Non-Migrated")
       Else
          Set sht = ActiveWorkbook.Sheets("Sheet1")
       End If
    & the same for the other sheet

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Call sheet name but sheet name may vary.

    
    Sub test()
    
    Dim sht As Worksheet
    
    MyArray = Array("Migrated", "Sheet1", "Non-Migrated", "Sheet2")
    
    For Count = 0 To UBound(MyArray) - 1
    On Error Resume Next
    ActiveWorkbook.Sheets(MyArray(Count)).Activate
    If ActiveSheet.Name = MyArray(Count) Then Exit For
    Next
    
    On Error GoTo 0
    
    Set WrkSht = ActiveSheet
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to go to a different Sheet from a For call
    By rcprito in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2015, 01:08 PM
  2. How to call a value in another sheet based on value in home sheet
    By TurbineTech85 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 10-17-2013, 11:24 AM
  3. Call sub for another sheet + when sheets name is string in sheet
    By Marianus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-30-2013, 04:28 PM
  4. Call sub for another sheet
    By Marianus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2013, 05:10 AM
  5. Call macro (Sheet 1) from any change in sheet 2
    By mark02 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2012, 10:29 PM
  6. Call the Sheet name
    By rbpd5015 in forum Excel General
    Replies: 1
    Last Post: 01-24-2011, 04:49 PM
  7. Call from a different sheet?
    By HisHighness in forum Excel General
    Replies: 3
    Last Post: 02-12-2006, 07:11 PM

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