2006-03-13, 19:16 #1
- Join Date
- Jan 2001
- Wellington, Wellington, New Zealand
- Thanked 0 Times in 0 Posts
Calculated name of variable (Any)
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")
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)
Subscribe to our Windows Secrets Newsletter - It's Free!
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!
+ 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!
2006-03-13, 19:20 #2
- Join Date
- Mar 2002
- 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)