Find activecell down a column

xluserg

Board Regular
Joined
Jan 30, 2010
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all hope your all well

I have this macro that i use to find the activecell value down a column I can use it in any column. The problem is if the data in the column is 2000 rows sometimes even more rows. Example: Row 100 Activecell value is Tom, find down Tom is in row 500 find again Tom is in row 1500 now there is no more Toms in the last 500 rows I don't know that so if I find down again the macro can take a long time to run maybe because it searching a million rows. How can I get the code to stop the search at the last value in the column at 2000 or more.

Sub FindDown_ThenStop()

Dim lngRow As Long

For lngRow = ActiveCell.Row + 1 To ActiveSheet.UsedRange.Row _
+ ActiveSheet.UsedRange.Rows.Count - 1
If Cells(lngRow, ActiveCell.Column).value = ActiveCell.value Then

On Error GoTo fin

Cells(lngRow, ActiveCell.Column).Select

Exit Sub
End If

Next

fin:
End Sub

Thanks in advance

Graham
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about
VBA Code:
Sub xluserg()
   Columns(ActiveCell.Column).Find(ActiveCell.Value, ActiveCell, , xlWhole, xlByRows, xlNext, False, , False).Select
End Sub
This will loop back to the 1st value in the column, if nothing is found below the active cell.
 
Upvote 0
Hi Fluff

When the code finds the last Tom and find again it goes back to the first Tom at the top of the column.

Is there anyway to stop at the last Tom if I run the code again?


Thanks for the quick reply

Graham
 
Last edited:
Upvote 0
When the code finds the last Tom and find again it goes back to the first Tom at the top of the column.
Yes I know, that's what I said it did. Do you want it to stop at the last Tom?
 
Upvote 0
Hi Fluff

I've not posted in while and I missed what you said sorry. Yes stop at the last Tom so if I ran the code it would do nothing.

Thanks

Graham
 
Upvote 0
Ok, how about
VBA Code:
Sub xluserg()
   Dim Fnd As Range
   Set Fnd = Columns(ActiveCell.Column).Find(ActiveCell.Value, ActiveCell, , xlWhole, xlByRows, xlNext, False, , False)
   If Fnd.Row > ActiveCell.Row Then Fnd.Select
End Sub
 
Upvote 0
Hi Fluff

Yes works Brilliant!

Thanks for your expertise.

All the best Fluff.

Graham
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top