+ Reply to Thread
Results 1 to 8 of 8

Tab names versus sheet1 name?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Tab names versus sheet1 name?

    When referring to worksheets in VBA, do you have to use the name on the sheet tab or can it simply be called Sheet1, Sheet2 etc? I have macro's that change the name of the tab, therefor I have been writing macro's for each of those scenarios (14), whereas if you can refer to the tab as a generic, such as sheet1, this would help a lot! What line would you use then to check if say sheet4 is visible, if so, continue, if not, skip to next sheet? Thanks!

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Tab names versus sheet1 name?

    You could refer in VBA to the sheetnumber.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Tab names versus sheet1 name?

    Hi, thecdnmole,

    you may refer to the code name of the sheets and use these as they could only be altered by VBA or in the VBE.

    Without further or deeper information on what you want to do:
    If Sheet4.Visible Then
      'do your stuff
    Else
      Sheet5.Select
    End If

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Tab names versus sheet1 name?

    Quote Originally Posted by HaHoBe View Post
    Hi, thecdnmole,

    you may refer to the code name of the sheets and use these as they could only be altered by VBA or in the VBE.

    Without further or deeper information on what you want to do:
    If Sheet4.Visible Then
      'do your stuff
    Else
      Sheet5.Select
    End If

    Ciao,
    Holger
    I started to have errors if the sheets were not visible, so the line between Else and End I just added the "'" and things worked. Now I found a post which says that line should be written like this...

    Sheet(5).Select

    This appears to be working now. Darn picky VBA for a newbie!

  5. #5
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Tab names versus sheet1 name?

    Thanks oeldere and HaHoBe. Music to my ears, but wish I knew that a month ago! Need to take a course on VBA! Thanks for the code to skip over sheets not visible, which now means using one macro for all scenarios!

  6. #6
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Tab names versus sheet1 name?

    Does the whole macro need to be done one way or the other or can you mix sheet15 with "Welcome"(tab name)? I just tried it in a macro and go an error on the line I changed. Is it entered as Sheet15, or do I need something else, like an exclamation mark??

  7. #7
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Tab names versus sheet1 name?

    Well that does not work either! If I use code names, when I run a different macro it appears that when I ask it to take the image from Sheet26 it takes it from another sheet! But if I put the tab name, Sheet("Welcome") it works. I thought if you use the sheet code name the macro should work no matter? Any ideas?

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Tab names versus sheet1 name?

    Hi, thecdnmole,

    the last question canīt be answered by anybody but you who sees both the code and the contents of the workbook, and I really doubt that
    Sheet(5)
    is correct as I think it should be
    Sheets(5)
    referring to the fifth sheet in the workbook (for me from the left side of the sheets no matter what kind of sheet the fifth is: worksheet, chart).

    Ciao,
    Holger

+ 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] Copy colors / names from Sheet2 to Sheet1
    By Berna11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-23-2013, 10:58 AM
  2. merge book1,sheet1,book2,sheet1,book3,sheet1 ect
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:30 PM
  3. [SOLVED] 3,000 Tables versus 3,000 Worksheets versus 3,000 Workbooks
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-18-2012, 03:15 AM
  4. Matching names from sheet2, sheet3, sheet4 with names in sheet1
    By Lynx2x in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-28-2012, 07:51 AM
  5. List Names on sheet2 ,but only names used in sheet1
    By 2Raw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2005, 12:10 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