0

I am looking for a RandBetween Altermative that has the exact same function but remains constant. I was looking for a macro that woould do just that and I thought I found one...

Function RndInt(lowerbound As Integer, upperbound As Integer) As Integer
Static AlreadyRandomized As Boolean

If Not AlreadyRandomized Then

Randomize

AlreadyRandomized = True

End If
RndInt = Int(lowerbound + Rnd() * (upperbound - lowerbound + 1))
End Function

After testing it, it looks like the problem is that the function doesn't choose between the cells but it only takes just the values of the upperbound and lowerbound cells and doesnt function as the RandBetween function where you can coose an upper and a lowerbound cell and it will pick from all the cells between these two cells :/

5
  • "maybe making my post unreadable" - yes:(. Apparently you've to issue - whether the macro works correctly, and how to use it correctly, please perform some tests to see which is the real issue, then edit your post and ask only the real question. Commented Aug 3, 2016 at 12:52
  • Yeap good advice... I will do that asap....
    – Silthatron
    Commented Aug 3, 2016 at 12:54
  • "I am looking for a RandBetween Altermative that has the exact same function but remains constant." - no your desired function have different functionality! (it chooses from cells values instead of chosing from range of numbers), which of your statements is true? The cited function does exactly the same as RANDBETWEEN Commented Aug 3, 2016 at 13:26
  • you may want to use =INDEX(A1:X1,RndInt(1,COLUMNS(A1:X1)) where A1 and X1 are first and last cells in your range. Commented Aug 3, 2016 at 13:27
  • yeap thats exactly what I want ;)
    – Silthatron
    Commented Aug 3, 2016 at 13:30

1 Answer 1

0

Your posted VBA does exactly what you described (RANDBETWEEN choose from a range of numbers, not from range of cells), maybe you should use it in a different way:

=INDEX(A1:X1,RndInt(1,COLUMNS(A1:X1))
where A1 and X1 are first and last cells in your range

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .