+ Reply to Thread
Results 1 to 5 of 5

How do you convert a string into a variable name?

  1. #1
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Question How do you convert a string into a variable name?

    Hello, I'm trying to setup a project so that all FILE UNIQUE constants are located in a "Global" module (for one-spot for an excel administrator to maintain) and declared as Public, and then used elsewhere in the project. The COUNT of these 'DataSheet' constants will vary from file to file (anywhere from 1 - ~15); and the NAMES of these Sheets follow NO particular structure whatsoever, could be any sort of name.
    I'm looking for code that will convert a string into a variable so to use in a For/Next loop to accommodate this variation in COUNT #. Bad thing is that the line "Applicaton.Sheets("DataSheet" & i).EnableCalculation" below faults.
    I'm looking for something kind of like the INDIRECT worksheet function. Does anything like that exist in VBA.

    If there is no way to do this, then another way would be to build-up an array in a SUB in the Global module. So, administrator would only have to go to this SUB and tweak this SUB for the various files. Is this the only way to do what I want???

    Please Login or Register  to view this content.
    Last edited by sauerj; 11-22-2010 at 11:59 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How do you convert a string into a variable name?

    Because all sheets belong to 1 collection you don't need to do it very complicatedly.
    No need for 'variable constants'.

    Please Login or Register  to view this content.



  3. #3
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: How do you convert a string into a variable name?

    The reasons for the Enable Calc (F/T) is to update OSI PI mfgr processing plant data that does NOT update from a normal 'Calculate'. The various Data Sheets (1 up to ~15) contain cells that pull in data from this OSI PI server. Besides these Data Sheets, there are many other sheets that do normal Excel functions referencing these various PI data cells. I don't want to perform this "Enable Calcs (F/T)" task on EVERY sheet as this takes extra time that is unnecessary. I only want to perform this task on the sheets that contain the PI data functions. The other cells that only reference the PI function cells will go ahead and automatically update (via the normal Automatic Calculate) once the PI cells change; no need to do this Enable Calc F/T thing on them.

    I had a 'For Each' collection loop, but now want to speed up this update process, so working on this modification led me to this question. ... I've got an array in the thing for now that the admin must manually tweak (and that isn't too bad), but the "Convert(String > Variable)" option would be a bit more user-friendly if such a trick existed. ... Any other ideas??? ... Thanks, sauerj
    Last edited by sauerj; 11-22-2010 at 05:55 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How do you convert a string into a variable name?

    Maybe ...
    Please Login or Register  to view this content.
    The / character is invalid in a sheet name, so splitting on it is safe.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Thumbs up Re: How do you convert a string into a variable name?

    Wow! ... You are one gifted dude! What an amazing use of this function! Essentially you can build ONE variable or constant that contains all the possible variable names strung together, and use this function to blow them apart & use them individually. This is so cool!

    To help newbies, the global constant declaration could be written out in a way for end users to see & better understand the pattern, so to more likely modify properly ... like as follows. Thanks for the enlightment. ... Solved!
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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