Can you combine variables?

DHS100

Board Regular
Joined
May 21, 2006
Messages
149
Hi,

I have a set of similar variables like this:
var_HasFinished1 = True
var_HasFinished2 = True
var_HasFinished3 = True
var_HasFinished4 = True
var_HasFinished5 = True

It would be very handy if instead of, for instance, saying something like:
if var_HasFinished1 = True then msgbox "Do Something to 1st process"

I could say:
if var_HasFinished & i = True then msgbox "Do Something to 1st process"
(the i would be a variable containing the value 1)

I've tried everything. I would be super grateful to anyone who knows how to do this or can think of a workaround!

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try using an array:

Code:
Sub test()
Dim var_HasFinished(1 To 6) As Boolean, i As Byte
For i = 1 To 6
    var_HasFinished(i) = True
    MsgBox var_HasFinished(i)
Next i
End Sub
 
Upvote 0
Some intro material on using array variables:

http://www.anthony-vba.kefra.com/vba/excelvba-simulation.htm#Creating_and_Managing_Array

You'll might want to note that if you declare an array such as
Code:
Dim hasFinished(5)
This is telling Excel to create an array such that its highest index number is 5. You might be thinking "Great! - 5 elements." However, the index is by default zero-based, so the elements of the array are hasFinished(0), hasFinished(1), hasFinished(2), hasFinished(3), and hasFinished(4), and hasFinished(5). As you see, this is six elements, not five.
You can either work with the zero base (programmers get used to this), or you can make Excel start at 1 by defined the base:
Code:
Dim hasFinished(1 to 5)
Now there would be no index of zero, and the first array Element is hasFinished(1).

HTH
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top