+ Reply to Thread
Results 1 to 4 of 4

Code required please

  1. #1
    Neal
    Guest

    Code required please

    Hi. Some help with this would be appreciated......

    I have a worksheet with a list of numbers in column "A".
    I would like a command button on the sheet that when pressed acivates an
    input box requseting the user to enter a number. When the number is entered
    the code would search column "A" and if a match is found then display this
    fact to the user. If no match is found then add the new number to the list
    and also advise the user that this has in fact been done.

    thanks in advance

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Hi
    hope this will get you started
    Please Login or Register  to view this content.
    rgds,
    jindon

  3. #3
    gocush
    Guest

    RE: Code required please

    How about something like:

    Option Explicit

    Sub FindMyNum()

    Dim rng As Range
    Dim NUM As Long
    Dim NextCell As Range

    Set NextCell = Range("A65536").End(xlUp)(2)
    NUM = InputBox("ENTER A NUMBER")

    Set rng = Range("A1", NextCell)
    With rng
    On Error Resume Next
    If IsError(.Find(WHAT:=NUM, AFTER:=NextCell).Select) Then
    MsgBox "Could not find your number. Will add it to the list.",
    vbOKOnly, ""
    NextCell = NUM
    Else
    MsgBox "Your number is located at: " & Selection.Address
    End If
    End With
    End Sub


    "Neal" wrote:

    > Hi. Some help with this would be appreciated......
    >
    > I have a worksheet with a list of numbers in column "A".
    > I would like a command button on the sheet that when pressed acivates an
    > input box requseting the user to enter a number. When the number is entered
    > the code would search column "A" and if a match is found then display this
    > fact to the user. If no match is found then add the new number to the list
    > and also advise the user that this has in fact been done.
    >
    > thanks in advance


  4. #4
    gocush
    Guest

    RE: Code required please

    How about something like:

    Option Explicit

    Sub FindMyNum()

    Dim rng As Range
    Dim NUM As Long
    Dim NextCell As Range

    Set NextCell = Range("A65536").End(xlUp)(2)
    NUM = InputBox("ENTER A NUMBER")

    Set rng = Range("A1", NextCell)
    With rng
    On Error Resume Next
    If IsError(.Find(WHAT:=NUM, AFTER:=NextCell).Select) Then
    MsgBox "Could not find your number. Will add it to the list.",
    vbOKOnly, ""
    NextCell = NUM
    Else
    MsgBox "Your number is located at: " & Selection.Address
    End If
    End With
    End Sub


    "Neal" wrote:

    > Hi. Some help with this would be appreciated......
    >
    > I have a worksheet with a list of numbers in column "A".
    > I would like a command button on the sheet that when pressed acivates an
    > input box requseting the user to enter a number. When the number is entered
    > the code would search column "A" and if a match is found then display this
    > fact to the user. If no match is found then add the new number to the list
    > and also advise the user that this has in fact been done.
    >
    > thanks in advance


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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