• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need help with VBA Code for generating lotto numbers

Status
Not open for further replies.
Ken,
yes, I did what you said above and that works... so then I try updating the column A list numbers, and when i do the numbers in column A go back to text..

this is the code which was given to me to bring numbers in from the prediction sheet when I click the Update List button:
Code:
Sub RowsOfNumbersToSingleColumn()
  Dim Cell As Range, Joined() As String, Nums(1 To 60) As String
  For Each Cell In Sheets("Predictions").Range("D12:R12,D14:R14,D16:R16,D18:R18,D20:R20,D32:M32,D33:K33,D34:I34,D36:M38,D37:K37,D38:I38")
    If CLng(Cell.Value) > 0 And CLng(Cell.Value) <= 60 And Len(Cell.Value) > 0 Then Nums(CLng(Cell.Value)) = Format$(Cell.Value, "00")
  Next
  Joined = Split(Application.Trim(Join(Nums)))
  With Sheets("Picks").Range("A1").Resize(UBound(Joined) + 1)
    .NumberFormat = "@"
    .Value = Application.Transpose(Joined)
  End With
End Sub

I noticed the red text... and wondered if this could be the problem, since the problem was happening when I clicked the button.. I searched for "VBA .Numberformat" and learned that the @ means Text.. and that "0" is for number. So I changed the code to "00" vice "@" and tried it.. it seems to work.. Can you confirm this?

Dave
 
Likely that is it. Change @ to 0#.

The Data Validation addition will help with inadvertent errors too. It is simple to do.

Changing the .numberformat="@" to .numberformat="0#" seems to nave fixed the issue i was having..

learned a little bit more.. at this rate I might be pretty good at this in about 10 years.... lol...

Thanks everyone for the help and support.

Dave
 
Good morning, i am an excel beginner and in my free time i made a random picking number lottery but the one that i have found here is much more better.I would ask you a favor, can you make 6 number picking instead of 5? I tried to modify the code but with no success. I attach an image for giving the idea of it and the file i was working on and which is the same that has been posted by Dwrowe001.

The 6 numbers should be picked by those on the column A. Thank you in advance and i hope to hear you soon,

Regards

Carlo
 

Attachments

  • Immagine.png
    Immagine.png
    35.7 KB · Views: 8
  • Copy CFL2.xlsm
    950.3 KB · Views: 8
Status
Not open for further replies.
Back
Top