Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Calculated name of variable (Any)

    Hi

    I have a timesheet macro that stores two sets of arrival and departure times for each day of the week then adds the lot up. The code is very repetitive. For example:<pre> Sat1 = FormatForDialog("Sat1")
    Sat2 = FormatForDialog("Sat2")
    Sat3 = FormatForDialog("Sat3")
    Sat4 = FormatForDialog("Sat4")
    etc, etc</pre>


    Is there any way of referring to a variable by its calculated name? Something along the lines of:<pre> For i = 1 to 4
    "Sat" & i = FormatForDialog("Sat" & i)
    Next i</pre>


  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Calculated name of variable (Any)

    The argument of FormatForDialog is a string, so you can use "Sat" & i there, but you cannot refer to a variable that way, but you could create an array:

    Dim Sat(1 To 7)
    Dim i As Integer
    For i = 1 To 7
    Sat(i) = FormatForDialog("Sat" & i)
    Next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •