Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a value in an excel column by vba code Cells.Find

Tags:

excel

vba

I have to find a value celda in an Excel sheet. I was using this vba code to find it:

Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _     xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _     xlNext, MatchCase:=False, SearchFormat:=False)   If cell Is Nothing Then     'do it something  Else     'do it another thing End If 

The problem is when I have to find the value only in a excel column. I find it with next code:

    Columns("B:B").Select     Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _         LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _         MatchCase:=False, SearchFormat:=False).Activate 

But I don't know how to adapt it to the first vba code, because I have to use the value nothing.

like image 298
Jonathan Raul Tapia Lopez Avatar asked Feb 18 '13 07:02

Jonathan Raul Tapia Lopez


People also ask

How do you search for a value in a column in Excel VBA?

To find a cell with a numeric value in an Excel Table, set the SearchDirection parameter to either of the following, as applicable: xlNext (SearchDirection:=xlNext): To search for the next match. xlPrevious (SearchDirection:=xlPrevious): To search for the previous match.


1 Answers

Just use

Dim Cell As Range Columns("B:B").Select Set cell = Selection.Find(What:="celda", After:=ActiveCell, LookIn:=xlFormulas, _         LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _         MatchCase:=False, SearchFormat:=False)  If cell Is Nothing Then     'do it something  Else     'do it another thing End If 
like image 176
Andrey Gordeev Avatar answered Sep 21 '22 07:09

Andrey Gordeev