I am trying to create a macro to loop through a set of 10 variables that may or may not be assigned values, if they are assigned a value then add the variable to an array. The variables all begin with hf and numbered 1 - 10. I am having difficulty figuring out how to retrieve the variable value while iterating through hf & 1-10 and then how I would add the variable to an array. In example below hf1, hf2 & hf5 would add values x, y & z to the array.
Any assistance is appreciated. Thank you.
Sub loop_through_i()
hf1 = "x"
hf2 = "y"
hf3 = ""
hf4 = ""
hf5 = "z"
hf6 = ""
hf7 = ""
hf8 = ""
hf9 = ""
hf10 = ""
For i = 1 To 10
If hf & i <> empty then
Set hf_array = Array("hf" & i)
End if
Next i
End Sub
Any assistance is appreciated. Thank you.
Sub loop_through_i()
hf1 = "x"
hf2 = "y"
hf3 = ""
hf4 = ""
hf5 = "z"
hf6 = ""
hf7 = ""
hf8 = ""
hf9 = ""
hf10 = ""
For i = 1 To 10
If hf & i <> empty then
Set hf_array = Array("hf" & i)
End if
Next i
End Sub