Find activecell down a column

xluserg

Board Regular
Joined
Jan 30, 2010
Messages
117
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
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,358
Office Version
  1. 365
Platform
  1. Windows
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.
 

xluserg

Board Regular
Joined
Jan 30, 2010
Messages
117
Office Version
  1. 365
Platform
  1. Windows
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,358
Office Version
  1. 365
Platform
  1. Windows
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?
 

xluserg

Board Regular
Joined
Jan 30, 2010
Messages
117
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,358
Office Version
  1. 365
Platform
  1. Windows
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
 

xluserg

Board Regular
Joined
Jan 30, 2010
Messages
117
Office Version
  1. 365
Platform
  1. Windows
Hi Fluff

Yes works Brilliant!

Thanks for your expertise.

All the best Fluff.

Graham
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,358
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,215
Messages
5,623,434
Members
415,974
Latest member
ZorroOP

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
Top