Random Data Generator part 2

I have a great little random generator macro that Glenn Ray and Kimputer wrote for me.  Only problem is the date field doesn't change correctly.  When you select the Frequency, it should adjust the date to reflect the selected frequency (e.g. day, month, year, sec., etc.) against the strart date.

That's it!

Thank you in advance,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn RayExcel VBA DeveloperCommented:
Hey...could you shorten the filename and re-attach?  EE can't handle long filenames and it's truncating the file extension.

I'll check it out shortly.

Bright01Author Commented:

Thank you!  

Glenn RayExcel VBA DeveloperCommented:
Hey B,

I found the error in my original code from your previous question.  The Select...Case section which determines the time increment (dblTime) was not finding "Min(s)" or "Sec(s)" and left dblTime as zero (0), so it did not show any increments.
Sub Generate_Samples()
    Dim lngFreq, r As Long
    Dim dtStart As Date
    Dim dblTime As Double
    Dim intMin, intMax As Integer
    lngFreq = Round(Range("D4"), 0)
    dtStart = Range("D5") + Range("D6")
    intMin = Range("C10").Value
    intMax = Range("C9").Value
    Select Case Range("C4").Value
        Case "Year(s)"
            dblTime = 365.04
        Case "Month(s)"
            dblTime = 30.42
        Case "Day(s)"
            dblTime = 1
        Case "Hour(s)"
            dblTime = 1 / 24
        Case "Min(s)"
            dblTime = 1 / 1440
        Case "Sec(s)"
            dblTime = 1 / 86400
    End Select
    'Clear existing data
    Range("C13:D" & Cells.SpecialCells(xlLastCell).Row).ClearContents
    'apply random values
    For r = 0 To lngFreq - 1
        Cells(r + 13, 3).Value = dtStart + (dblTime * r)
        Cells(r + 13, 4).Value = WorksheetFunction.RandBetween(intMin, intMax)
    Next r
    MsgBox ("Done.")
End Sub

Open in new window

I updated the code to match your sheet layout (Max/Min in that order; your drawing object to run).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bright01Author Commented:
Great!  Works like a champ.  On to the next level.  I will be using this to generate test data for sensor based readings of assets for Asset Optimization.  Thanks again....great work!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.