I am a newby to VBA and below I am trying to generate a random number between 3000 and 3777, but it doesn't work. It only goes through once then quits producing all kinds of numbers outside the desired range. Here is my code:
Option Explicit
Sub Enter_Click()
Dim BCN As Integer
Dim BCN1 As Integer
Dim BCN2 As Integer
Do
Range("D6") = Rnd() * 10000
Loop Until Range("D6").Value >= 3000 <= 3700
BCN = ActiveSheet.Range("D6").Value
ActiveSheet.Shapes("BCN1").Select
Selection.Characters.Text = BCN
ActiveSheet.Shapes("BCN2").Select
Selection.Characters.Text = BCN
' the above code is supposed to loop until a random number between
' 3000 and 3777 is produced, but it doesn't work. It only goes
' through once as if the do loop isn't even there, then quits.
End Sub
What am I doing wrong??
Your Loop Until line isn't correctYou could try the RANDBETWEEN Function instead and skip the Do loopLoop Until Range("D6").Value >= 3000 And Range("D6") <= 3700Lastly, if you're expecting Shapes("BCN1") to convert to Shapes(32141) (or somesuch), it won't because the BCN is inside quotation marks and won't be seen as a variable. Hope that helped.Range("D6") = WorksheetFunction.RandBetween(3000, 3700)
ChemistB
My 2¢
Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)
Making the world a better place one fret at a time
||||||
If someone helped you, please click on the star icon at the bottom of their post
If your problem is solved, please update the first post:
EDIT, Go Advanced button, set Prefix to SOLVED
[code]
' Enclose code in tags like this
[/code]
Don't attach a screenshot--just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks