Selecting The Last Cell containing specific text doesn't work

CaptainCsaba

Board Regular
Joined
Dec 8, 2017
Messages
78
Hi!

I am trying to select the last cell in column A that contains numbers with the thousand separators eg 1,234,567. Previously in one of my other codes I used "*#,#*" but here it does not seem to work. If I write anything instead it perfectly finds it but not like this. What am I missing?

Code:
Sub SelectLastCell()Dim lr, i, n As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For i = lr To 2 Step -1
    On Error Resume Next
    n = WorksheetFunction.Search("*#,#*", Cells(i, 1))
    If Err = 0 Then
        Cells(i, 1).Select
        Exit For
    End If
Next i
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Perhaps :
Code:
Sub SelectLastCell()
Dim lr as Long, i as Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
    If Cells(i, 1) >= 1000 Then
        Cells(i, 1).Select
        Exit For
    End If
Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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