+ Reply to Thread
Results 1 to 13 of 13

Generate a random number

  1. #1
    Registered User
    Join Date
    04-09-2014
    Location
    Sweden
    MS-Off Ver
    MS 365 version 2302
    Posts
    20

    Generate a random number

    Hi guys,

    If column A has the same value as the previous line and the sum of column B is less than 3 I want that group to have unique number in column C for that group.

    Please see attached file.. hard to explain this

    Br,
    Mikael

    Col A Col B Col C
    A 1 ABC123
    A 2 ABC123
    A 3 ABC123


    A 1 SSD111

    B 1 ABC456
    B 2 ABC456


    C 1 DDD
    D 1 DDD11
    D 2 DDD11
    D 3 DDD11

    help.xlsxhelp.xlsx
    D 1 TEST1
    D 2 TEST1
    D 3 TEST1


    D 1 TEST2
    D 2 TEST2
    D 3 TEST2


    D 1 TEST33
    D 2 TEST33

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,466

    Re: Generate a random number

    What happens if there are four or more?

    In B3 copied down:

    =COUNTIFS(A$3:A3,A3,C$3:C3,C3)
    Last edited by AliGW; 08-22-2023 at 11:03 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-09-2014
    Location
    Sweden
    MS-Off Ver
    MS 365 version 2302
    Posts
    20

    Re: Generate a random number

    There is a file attached already.

    help.xlsx

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,466

    Re: Generate a random number

    Yes, I found it - wasn't very obvious!

    See post #2.

  5. #5
    Registered User
    Join Date
    04-09-2014
    Location
    Sweden
    MS-Off Ver
    MS 365 version 2302
    Posts
    20

    Re: Generate a random number

    Hi,

    If there is more than three, then a new random number should be generated for the new dataset. That is what I tried to illustrate.. but hard to explain. Sorry.

    If is the reference in column C that I want to create.

    So if Column A is the same value like it for line 3-5 and the count is less than 4 I want a unique number generated for those lines. In the example that is ABC123.

    Customer Counter Reference
    A 1 ABC123
    A 2 ABC123
    A 3 ABC123
    A 1 SSD111
    B 1 ABC456
    B 2 ABC456
    C 1 DDD
    D 1 DDD11
    D 2 DDD11
    D 3 DDD11
    D 1 TEST1
    D 2 TEST1
    D 3 TEST1
    D 1 TEST2
    D 2 TEST2
    D 3 TEST2
    D 1 TEST33
    D 2 TEST33

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,466

    Re: Generate a random number

    I don’t follow - sorry.

  7. #7
    Registered User
    Join Date
    04-09-2014
    Location
    Sweden
    MS-Off Ver
    MS 365 version 2302
    Posts
    20

    Re: Generate a random number

    Ok. See the new file that I attached.

    help2.xlsx

  8. #8
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Generate a random number

    Try this in B12:

    =IFERROR(VLOOKUP(A12,$A$11:B11,2,0),MAX($B$11:B11)+1)

  9. #9
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    3,183

    Re: Generate a random number

    Try this in cell C3 and copy down:
    =IF($B3>$B2,$C2,RAND())
    You don't mention how to generate the random number so I just put this in. It can be tailored to how you need it
    EDIT: I said C3 above because I didn't see your second file.
    Last edited by Gregb11; 08-22-2023 at 09:11 PM.

  10. #10
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,896

    Re: Generate a random number

    Try this in C12.

    Please Login or Register  to view this content.
    copied down.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-09-2014
    Location
    Sweden
    MS-Off Ver
    MS 365 version 2302
    Posts
    20

    Re: Generate a random number

    Thank you guys! This is just great!

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,466

    Re: Generate a random number

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  13. #13
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,896

    Re: Generate a random number

    You are welcome.

+ 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. How can i generate a random number between 0.8 and 1.2
    By hawkinsr86 in forum Excel General
    Replies: 4
    Last Post: 01-03-2014, 10:03 AM
  2. Replies: 8
    Last Post: 11-18-2013, 04:24 PM
  3. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  4. [SOLVED] How to generate a random number?
    By frankk119 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2012, 09:19 AM
  5. [SOLVED] Generate random 6-16-byte random hexadecimal number
    By jsamuelshn in forum Excel General
    Replies: 6
    Last Post: 07-20-2012, 10:38 AM
  6. Generate a random number
    By psatala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2011, 02:51 PM
  7. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM
  8. [SOLVED] Generate Random Number
    By Glenn in forum Excel General
    Replies: 1
    Last Post: 08-11-2005, 03:05 PM

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