+ Reply to Thread
Results 1 to 3 of 3

Need to program a find only in one column

  1. #1
    Registered User
    Join Date
    03-31-2006
    Posts
    2

    Need to program a find only in one column

    Hi. I need to use the find tool in Excel but only for one column. How I can do this? I have this:

    Private Sub cmdTSearch_Click()
    Dim DATA As String
    DATA = txtTicket.Text

    If txtTicket.Text = "" Then
    MsgBox ("Text Box Empty")
    Else
    With Worksheets("Info").Range("X4:X700")
    Set B = Cells.Find(What:=DATA, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=True)

    If B Is Nothing Then
    MsgBox ("Nothing Found")
    Else
    Range("X4:X500").Select
    Cells.Find(What:=DATA, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=True).Activate

    End If

    'MsgBox ActiveWindow.RangeSelection.Address

    End With
    End If
    End Sub


    Thanks.
    Angel

  2. #2
    JMB
    Guest

    RE: Need to program a find only in one column

    I think you need a period in front of Cells (otherwise it refers to all of
    the cells on the worksheet). You probably also want to qualify After to use
    the first cell in X4:X700 instead of the active cell (but I've not tested to
    see if it makes a difference).

    With Worksheets("Info").Range("X4:X700")
    Set B = .Cells.Find(What:=DATA, After:=.Cells(1,1), LookIn:=xlValues

    Also, at the end of your code, if B is not nothing you should not have to
    perform the Find operation again, just activate the cell with

    B.Activate

    assuming the worksheet containing B is the active sheet (otherwise, you have
    to activate the proper worksheet, then activate B).

    "xrckiss" wrote:

    >
    > Hi. I need to use the find tool in Excel but only for one column. How I
    > can do this? I have this:
    >
    > Private Sub cmdTSearch_Click()
    > Dim DATA As String
    > DATA = txtTicket.Text
    >
    > If txtTicket.Text = "" Then
    > MsgBox ("Text Box Empty")
    > Else
    > With Worksheets("Info").Range("X4:X700")
    > Set B = Cells.Find(What:=DATA, After:=ActiveCell, LookIn:=xlValues,
    > LookAt:= _
    > xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
    > MatchCase:= _
    > False, SearchFormat:=True)
    >
    > If B Is Nothing Then
    > MsgBox ("Nothing Found")
    > Else
    > Range("X4:X500").Select
    > Cells.Find(What:=DATA, After:=ActiveCell, LookIn:=xlValues,
    > LookAt:= _
    > xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
    > MatchCase:= _
    > False, SearchFormat:=True).Activate
    >
    > End If
    >
    > 'MsgBox ActiveWindow.RangeSelection.Address
    >
    > End With
    > End If
    > End Sub
    >
    >
    > Thanks.
    > Angel
    >
    >
    > --
    > xrckiss
    > ------------------------------------------------------------------------
    > xrckiss's Profile: http://www.excelforum.com/member.php...o&userid=33065
    > View this thread: http://www.excelforum.com/showthread...hreadid=528787
    >
    >


  3. #3
    Registered User
    Join Date
    03-31-2006
    Posts
    2
    Thanks JMB. Worked just fine.

+ 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