+ Reply to Thread
Results 1 to 3 of 3

Accessing the data in an array in a different sub

  1. #1
    Registered User
    Join Date
    02-27-2020
    Location
    England
    MS-Off Ver
    Excel 2010 and 365
    Posts
    2

    Unhappy Accessing the data in an array in a different sub

    Hi,

    I am very good at excel until it comes to using VBA. I just don't get it.

    I am trying to stop anybody changing the names of tabs if the tabs are protected. I could relatively easy stop the renaming of them altogether with a private sub for each sheet saying if the sheet name <> 'whatever it is currently called', it gets set back to 'whatever it is currently called'. However, I want them to be able to change them if they are unprotected (each sheet will at times be protected and at other times not). I don't want the name being set back to 'whatever it is currently called' if it has undergone two or three legitimate name changes since I wrote the code.

    With that in mind, I wrote a macro, which I think works, to store, before save, all the names of the tabs in an array.
    Please Login or Register  to view this content.
    What I want to do is to have a workbook macro, on sheetselectionchange, that compares the name of the active sheet with the corresponding entry in WSArray. I think I can use ActiveSheet.Name on the one side and ActiveSheet.Index as the entry number in the array. I just can't work out how to get the array into another sub. I have looked at examples on the web but they don't actually explain step by step how the thing works. I would be very grateful for any help.

    Thank you.
    Last edited by Leith Ross; 02-27-2020 at 01:58 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Accessing the data in an array in a different sub

    Hello rockhyrax123,

    Welcome to the forum!

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-27-2020
    Location
    England
    MS-Off Ver
    Excel 2010 and 365
    Posts
    2

    Re: Accessing the data in an array in a different sub

    Thank you, that was helpful.

    I am now having other issues though.

    I am getting a type mismatch between ActiveSheet.Name and WSArray(ActiveSheet.Index). ActiveSheet.Name seems to be a variant but I can't work out what type WSArray(ActiveSheet.Index) is. CVAr(WSArray(ActiveSheet.Index) doesn't work either.

+ 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. Accessing a global array variable from within a cell
    By gil64 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2019, 06:29 PM
  2. Function accessing array values
    By Alexander40 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2018, 02:05 AM
  3. [SOLVED] Issue Accessing Public Multidimensional Array in Another Module
    By Sprucie in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-24-2016, 06:05 AM
  4. [SOLVED] Accessing an array of form textboxes
    By Bucephalus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2015, 07:46 AM
  5. [SOLVED] Accessing array in a class module
    By chipnputt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2014, 11:09 PM
  6. Accessing a 'column' in a VB array
    By den1s in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2006, 06:10 AM
  7. [SOLVED] Type mismatch accessing variant array too many times
    By peter in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2005, 07:06 PM

Tags for this Thread

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