Variable in Function name

Jaamie

Board Regular
Joined
Apr 16, 2003
Messages
224
Office Version
  1. 2016
Platform
  1. Windows
I have several functions named Test1(), Test2(), ..., etc.

I want to be able to say If TestX() = True then ...

How can I accomplish going to one particular test at run time based on the value of X?

Thank you,
Jim..
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
try...

Code:
for X=1 to 10
if "test" & X &"()" = true then
...your code
endif
next
 
Upvote 0
But did either or both of them work?

If you report back with your findings - and maybe post the code you ended up using - your answer will be recorded for posterity and future generations of seekers will have this knowledge readily available at their fingertips!
 
Upvote 0
But did either or both of them work?

If you report back with your findings - and maybe post the code you ended up using - your answer will be recorded for posterity and future generations of seekers will have this knowledge readily available at their fingertips!


Good idea...I agree
 
Upvote 0
Neither of them worked.

if "test" & X &"()" = true then

this just fell through to the next statement; and

If Evaluate("Test" & x & "()") Then

went to some random place. I had x=1 and put a stop on the 1st statement in Function Test1(). It didn't go to Test1(); rather I got a Message that comes from elsewhere in the code?
 
Upvote 0
Neither of them worked.

if "test" & X &"()" = true then

this just fell through to the next statement; and

If Evaluate("Test" & x & "()") Then

went to some random place. I had x=1 and put a stop on the 1st statement in Function Test1(). It didn't go to Test1(); rather I got a Message that comes from elsewhere in the code?

Then the problem would be not in IF's but in your Function itself because it calls your Function and the codes in your function brings the error...
Would you mind sharing it to give it a try?
Thanks
 
Upvote 0
Below the code to get to Rule2() works and I have similar code for 10 other functions named Teat1() thru Test10()

I am trying to streamline all this code into a simple loop calling each Function in turn until I get a True result

The test for the modified code for Rule1() comes first

Do
CanBeChangeFlag = False 'exit only after a complete pass with no change
If CanBeChangeFlag = False Then
x = 1
If Evaluate("Rule" & x & "()") = True Then
CanBeChangeFlag = True
End If
End If ' See if any cell has only one possible candidate

If CanBeChangeFlag = False Then ' Rule 2: Only once in mode M
CanBeChangeFlag = Rule2()
End If
.
.
Loop Until CanBeChangeFlag = True

..
Function Rule1()
Rule1 = False
For I = 1 To 9: For J = 1 To 9
CanLoc = ((I - 1) * 9) + J
If CanLoc = 48 Then
Z$ = ""
End If
If Len(CanB$(CanLoc)) = 2 Then 'Only 1 # in a CanB entry, it Must Be
Rule1 = True: Actn$ = "Only choice for cell"
TNum = Val(Left(CanB$(CanLoc), 1))
If PostChoice(TNum, I, J, Actn$) = False Then End
J = 10: I = 10
End If
Next J: Next I
End Function 'Rule1
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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