Variable Variable??
Posted by RoB on August 21, 2001 10:54 AM
I am trying to put a loop into a macro which pretty much everyone on this board has helped me with (thanks to you all). I have created a piece of code to do what I want it to, but I know the syntax is incorrect for VB (as I dont know it) and also, I don't know if my method will work... heres the code: (This isnt the whole macro, only the necessary parts)
Dim NumberConditions as Integer
Dim Counter as Integer
Dim FilterCriteria
NumberConditions = InputBox("Enter # of conditions to filter")
For Counter = 1 to NumberConditions
FilterCriteria(Counter) = InputBox("Enter Criteria Counter")
Next
Selection.AutoFilter field:=ColumnFilterSelect, Criteria1:=FilterCriteria1this part needs to be modified to contain how ever many criteria the user selects, ie: if the user says 3 criteria, it would read: Criteria1:=FilterCriteria1, Criteria2:=FilterCriteria2, Criteria3:=FilterCriteria3
What I want to be able to do is define a variable using a varible. for example, the FilterCriteria(Counter). so when this is on the first counter, it will read FilterCriteria1= whatever user inputs... Is this possible, or am I way off track and theres a WAY simpler way? I think the defining is going to be a problem because the variables say, FilterCriteria2 would not be defined. Also, how would I in the last part get the Criteria2:=FilterCriteria2. Woudl this require another loop?
Thanks for any input :)