Jeffrey Smith
Well-known Member
- Joined
- Feb 11, 2005
- Messages
- 795
Ok, so I thought I'd seen this before but I can't seem to come across it in the forums.
I've created my own search routine. Once the first value has been found, I want to find the next value that meets the criteria without having to search all the previous cells. The end user highlights a range of cells and starts the user form. Instead of having to manually find the last cell in the highlighted range, isn't there a way to identify the last cell in the range?
Something like: Set LastCell = Rng.last
This code finds the next cell to search and the last cell in the highlighted range and saves it to SearchRng so the GoFindIt code can use it:
I've created my own search routine. Once the first value has been found, I want to find the next value that meets the criteria without having to search all the previous cells. The end user highlights a range of cells and starts the user form. Instead of having to manually find the last cell in the highlighted range, isn't there a way to identify the last cell in the range?
Something like: Set LastCell = Rng.last
This code finds the next cell to search and the last cell in the highlighted range and saves it to SearchRng so the GoFindIt code can use it:
Code:
Private Sub FindNext_Click()
Dim Cell As Range
Dim Rng As Range
Dim Test As Integer
Dim NextCell As Range
Set Rng = Selection
For Each Cell In Rng
If Test = 0 And Cell.Address = ActiveCell.Address Then
Test = 1
ElseIf Test = 1 Then
Set NextCell = Cell
Test = -1
End If
Set LastCell = Cell
Next Cell
Set SearchRng = Range(NextCell, LastCell)
Call GoFindIt
End Sub