PDA

View Full Version : Solved: Need help creating a function with loop.



gabethegrape
03-17-2009, 01:34 AM
This one has been giving me a lot of trouble. I'm trying to create a function that uses two input values selected in a userform to produce a desired output (please see attachment). The problem I'm having is that I'm creating a separate function for each "dynamic variable" and so I've got 25 output values when I'd like to have only one. Is this possible? My guess is that a loop needs to be created with different step values (I just don't know how to do that).
Any help is greatly appreciated.
Gabe

Simon Lloyd
03-17-2009, 01:40 AM
As a general helper (because i don't have time right now to look at your attachment) you can use Select Case like this:
Assuming for this purpose we are looking at the value of A1
Select Case Sheets("Sheet1").Range("A1")
Case Is = 1
Sheets("Sheet2").Range("A1")= "One"
Case Is = 2
Sheets("Sheet2").Range("A2")= "Two"
Case Is = 3
Sheets("Sheet2").Range("A3")= "Three"
End Select
It's not a loop and is very efficient, you can just keep extending the terms, hope it helps some way!

Bob Phillips
03-17-2009, 01:57 AM
That workbook contains nothing, no userform, no code, just a sparse bit of data.

gabethegrape
03-17-2009, 02:10 AM
Thanks Simon, I tried the Select Case method and it seems to be working well. Cheers,
Gabe

Simon Lloyd
03-17-2009, 03:22 PM
If your question is solved please mark it solved by going to thread tools!