Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Random Number Generator

  1. #11
    MrExcel MVP
    Join Date
    May 2009
    Posts
    15,548
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Random Number Generator

    While we're nit picking, Rick your code will have a run time error if there are no blank cells in the target range.
    Last edited by JoeMo; Apr 16th, 2018 at 01:08 PM.
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  2. #12
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    32,794
    Post Thanks / Like
    Mentioned
    52 Post(s)
    Tagged
    17 Thread(s)

    Default Re: Random Number Generator

    Quote Originally Posted by JoeMo View Post
    While we're nit picking, Rick your code will have a run time error if there are no blank cells in the target range.
    That is a good nit given it could be possible that the OP might not know if there are any blanks to be filled or not. Corrected code below...
    Code:
    Sub FillBlanksWithRandomTempNumber() Dim RandNum As Long, Cell As Range, Blanks As Range, Nums As String On Error GoTo NoBlanks For Each Cell In Range("A1", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlBlanks) Do RandNum = Application.RandBetween(10000000, 99999999) Loop While InStr(" " & Nums & " ", " " & RandNum & " ") Nums = Nums & " " & RandNum Cell.Value = "TEMP" & RandNum Cell.EntireRow.Font.Color = vbRed Next NoBlanks: End Sub
    Last edited by Rick Rothstein; Apr 16th, 2018 at 01:35 PM.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  3. #13
    Board Regular Sharid's Avatar
    Join Date
    Apr 2007
    Posts
    410
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Random Number Generator

    If your gone fight, why not fight over this little problem I have.

    https://www.mrexcel.com/forum/excel-...t-records.html

    The one who sorts it can be the champ. lol
    If I could code in VB, life wouldn't be such a pain in the A$$

  4. #14
    MrExcel MVP
    Join Date
    May 2009
    Posts
    15,548
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Random Number Generator

    Quote Originally Posted by Sharid View Post
    If your gone fight, why not fight over this little problem I have.

    https://www.mrexcel.com/forum/excel-...t-records.html

    The one who sorts it can be the champ. lol
    Fight? We don't fight, we just strive to give you the perfect solution to fit your need.

    As for your little problem, you could improve your chances of getting help by posting some sample data that reflects what you start with and what you would like to see after the solution is applied, all in a format that can be copied from a browser and pasted to Excel. That would remove considerable labor and exchange of posts from the task of provision of a solution.
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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