[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

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,

  • 2
  • 2
1 Solution
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).

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!


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now