Need to program a find only in one column

X

xrckiss

Hi. I need to use the find tool in Excel but only for one column. How I
can do this?:rolleyes: 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
 
G

Guest

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top