Hi!
I don't want to search for a value just after a cell, or before that. How could I perform that?
The value of A10 is in Cells of B1, B3, B7, and B16 too.
If I search for the value of A10, then i don't want to get B16, because it looks for the value with a direction of "xlNext". I need B1, than if I search again, then B3, and if I search again B7 and so on.
There is a button, and the following macro is added to it:
Sub searchActiveCellInColumnN()
Dim CurrValue As String
Dim foundcell As Range
CurrValue = ActiveCell.Value
If Len(CurrValue) = 0 Then Exit Sub
Set foundcell = Sheets(1).Columns("N:N").Find(What:=CurrValue, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False) 'SearchDirection:=xlNext, *
If Not foundcell Is Nothing Then
Sheets(1).Activate
foundcell.Select
Else
'not found
MsgBox CurrValue & Chr(10) & "Record Not Found", 48, "Not Found"
End If
End Sub
Any idea, how to make my button work, so it always looks for the active cell's content from the start of that column, and for every next "run" of the code it gives the next match in that column. Could you modify it? Have a very nice day!
I don't want to search for a value just after a cell, or before that. How could I perform that?
The value of A10 is in Cells of B1, B3, B7, and B16 too.
If I search for the value of A10, then i don't want to get B16, because it looks for the value with a direction of "xlNext". I need B1, than if I search again, then B3, and if I search again B7 and so on.
There is a button, and the following macro is added to it:
Sub searchActiveCellInColumnN()
Dim CurrValue As String
Dim foundcell As Range
CurrValue = ActiveCell.Value
If Len(CurrValue) = 0 Then Exit Sub
Set foundcell = Sheets(1).Columns("N:N").Find(What:=CurrValue, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False) 'SearchDirection:=xlNext, *
If Not foundcell Is Nothing Then
Sheets(1).Activate
foundcell.Select
Else
'not found
MsgBox CurrValue & Chr(10) & "Record Not Found", 48, "Not Found"
End If
End Sub
Any idea, how to make my button work, so it always looks for the active cell's content from the start of that column, and for every next "run" of the code it gives the next match in that column. Could you modify it? Have a very nice day!
Last edited: