+ Reply to Thread
Results 1 to 4 of 4

Random number generated, then fixed for list of values challenge

Hybrid View

  1. #1
    Registered User
    Join Date
    09-22-2009
    Location
    Mumbai India
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    77

    Random number generated, then fixed for list of values challenge

    Hi all, I've a number of problems to solve for and am testing with random numbers as that's what I'll have to actually work with however, once the first random number is generated, I need to fix the number and run the rule on the next line from the (now) fixed first value, again with a random number for line two.

    The idea is to test a trading strategy where all lines represent a new trade and we start with the balance from the previous trade which is why each time a random number is generated to represent the trade strategy, it needs to be locked so the next line is not suddenly changed.

    The inputs are:

    Starting balance and finish balance
    The market price (random each time a trade is generated)
    Value of trade - decided by rules, but any numbers can be used even $10 a trade to represent a transaction.

    This is little more that an idea right now and I would value any support on how to generate a line item and then fix it. Maybe a macro and a button to generate as many line items as I specify and run a rule for all data. I have no experience with macros or VBA..

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Random number generated, then fixed for list of values challenge

    some thing like this

    Sub Generate_random_Nbrs()
    Dim Sht As Worksheet: Set Sht = Sheets("Sheet1")
    frn = InputBox("Please Enter First Number to Fix", "First Random Nbr")
    With Sht
        .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row + 1).ClearContents
        .Range("A2").Value = frn
        lrn = InputBox("Please Enter No.of Lines to generate Random Numbers(Should be Morethan 3)", "Random Nbrs")
        For i = 3 To lrn
            .Range("A" & i).Value = Int((999 - frn + 1) * Rnd + frn)
                'Result: random number between frn enter nbr and 999
        Next
    End With
    End Sub
    Attached Files Attached Files
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Registered User
    Join Date
    09-22-2009
    Location
    Mumbai India
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    77

    Re: Random number generated, then fixed for list of values challenge

    Wow that's really great thank you! I'll play with this later with some other data and see how it works out! Many thanks for your swift response.

  4. #4
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Random number generated, then fixed for list of values challenge

    Quote Originally Posted by smudgepost View Post
    Wow that's really great thank you! I'll play with this later with some other data and see how it works out! Many thanks for your swift response.
    Glad to help

    please mark thread as SOLVED if its resolve & Click on * Add Reputation to say thanks...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 10-08-2014, 08:35 AM
  2. [SOLVED] Random Number Generated from Truncated Distribution
    By love_sick7 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2014, 10:57 AM
  3. Replies: 5
    Last Post: 01-12-2014, 03:40 AM
  4. Random number generation for a fixed given sum
    By abhi16.2007 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-08-2013, 08:00 AM
  5. random answers generated from a list
    By juicy fruit in forum Excel General
    Replies: 9
    Last Post: 04-11-2010, 07:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1