Consulting

Results 1 to 2 of 2

Thread: search data from other worksheet

  1. #1

    search data from other worksheet

    hi it's me again...

    i created a random number generator with the help of matt and others... well i want to experiment..

    what i want now is that.. when i generate a random generator after that search the winning number from diffirent worksheet to find out if someone won?

    can you please help me?

    here is the code of my generator

    [vba]

    Option Explicit
    Private Sub CommandButton1_Click()

    Dim vTime As Date, vNumber As String, i As Long, j As Long, k As Long

    UserForm1.TextBox5.Visible = False
    UserForm1.Label3.Visible = False



    Randomize
    vNumber = Format(Int(Rnd * 1629 + 1), "0000")


    For i = 1 To 4
    vTime = Now
    Do Until Now > vTime + TimeValue("00:00:01")
    Randomize
    If i = 1 Then
    TextBox1.Text = CStr(Int(Rnd * 2))
    k = 2
    Else
    k = i
    End If
    For j = k To 4
    Me.Controls("TextBox" & CStr(j)).Text = CStr(Int(Rnd * 10))
    Next
    DoEvents
    Loop
    Me.Controls("TextBox" & CStr(i)).Text = Mid(vNumber, i, 1)
    Next

    UserForm1.TextBox5.Visible = True
    UserForm1.Label3.Visible = True


    Sheet1.Cells(Rows.Count, "A").End(xlUp)(2, 1) = TextBox1.Text
    Sheet1.Cells(Rows.Count, "B").End(xlUp)(2, 1) = TextBox2.Text
    Sheet1.Cells(Rows.Count, "C").End(xlUp)(2, 1) = TextBox3.Text
    Sheet1.Cells(Rows.Count, "D").End(xlUp)(2, 1) = TextBox4.Text
    Sheet1.Cells(Rows.Count, "D").End(xlUp).Offset(0, 1).Value = TextBox5.Text
    TextBox5 = ""
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub

    Private Sub CommandButton2_Click()
    Unload Me
    End Sub

    Private Sub Label3_Click()

    End Sub

    Private Sub TextBox5_Change()
    Sheet1.Cells(Rows.Count, "D").End(xlUp).Offset(0, 1).Value = TextBox5.Text
    End Sub

    Private Sub UserForm_Initialize()

    Call RemoveCaption(Me)


    End Sub

    [/vba]

    thanks waiting for someone to help me

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Have you looked at the Find method in VBA help? That should be able to do what you want (though you probably will want to store the entire number in a cell, not each digit in 4 separate cells)
    Matt

Posting Permissions

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