Results 1 to 2 of 2

Thread: Alter existing code to include new functions

  1. #1
    Neophyte johnmason's Avatar
    Join Date
    May 2021
    Posts
    1
    Articles
    0
    Excel Version
    MS Excel2016

    Question Alter existing code to include new functions



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Code "GenerateRandom" generates random numbers.
    Is there a way of selecting the numbers from a range of date sets to generate random numbers onto another sheet?

    I have attached a workbook with the code.

    If so I would appreciate some help.

    Code:
    Option Explicit
    Option Base 1
    Public jj As Long
    Public Const iteration = 100
    
    '***********************************************************************
    '*                                     Generate Sampling Process                                       *
    '***********************************************************************
    
    Sub GenerateRandom()
        Dim i As Long
        Dim hold(100) As Single, Hold2(100) As Single
        Randomize
    
        For i = 1 To 100
                  Hold2(i) = i
        Next i
    
         For jj = 1 To iteration
    
             For i = 1 To 100
                hold(i) = Rnd
            Next i
    
             Call DoubleSort(100, hold, Hold2)
    
             For i = 1 To 14
                Cells(jj + 3, i) = Hold2(i)
            Next i
      
        Next jj
    
    End Sub
    
    '***********************************************************************
    '*             Sorting Process -  Sort array y based on array x                 *
    '***********************************************************************
    
    Sub DoubleSort(n As Long, x() As Single, y() As Single)
        Dim xTemp As Double
        Dim yTemp As Double
        Dim i As Long
        Dim j As Long
    
        For j = 2 To n
    
             xTemp = x(j)
            yTemp = y(j)
    
                 For i = j - 1 To 1 Step -1
                    If (x(i) <= xTemp) Then GoTo 10
                    x(i + 1) = x(i)
                    y(i + 1) = y(i)
                Next i
    
             i = 0
    10   x(i + 1) = xTemp
            y(i + 1) = yTemp
    
         Next j
    
    End Sub
    Last edited by p45cal; 2021-05-07 at 11:20 PM. Reason: added code tags

  2. #2
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,948
    Articles
    0
    Excel Version
    365
    Quote Originally Posted by johnmason View Post
    I have attached a workbook with the code.
    No you haven't.
    The code isn't enough - we need to know more about the 'range of date' sets and the kind of 'numbers' you want on which sheet.
    Last edited by p45cal; 2021-05-18 at 10:55 PM.

Posting Permissions

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