Consulting

Results 1 to 5 of 5

Thread: Solved: Need help creating a function with loop.

  1. #1

    Solved: Need help creating a function with loop.

    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

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    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
    [VBA]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
    [/VBA]It's not a loop and is very efficient, you can just keep extending the terms, hope it helps some way!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That workbook contains nothing, no userform, no code, just a sparse bit of data.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks Simon, I tried the Select Case method and it seems to be working well. Cheers,
    Gabe

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    If your question is solved please mark it solved by going to thread tools!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •