Last Row in Dataset? VBA

Phlip183

New Member
Joined
Jun 9, 2011
Messages
10
Hi, Im looking for some VBA code that will find the last row that I specify. For example:

There are 4 A's and 5 B's in Coulmn A (total of 9 rows). How do i find the last A before the B's start? The code would have to be a variable so i can enter in what ever type of text i wanted.

Thanks for the help!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try like this

Code:
Sub test()
Dim s As Variant, LR As Long
s = InputBox("Enter search value")
LR = Columns("A").Find(What:=s, SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
MsgBox LR
End Sub
 
Upvote 0
Thanks for the quick response Vog, but not exactly. I dont really want a text box to show up so i (as the user) can find the specific value, i want to edit it in the code myself so it can be part of a fully automated process i am working on.

And also, the other problem is that once i enter in the text i need to search on, it doesnt select the last value/text, it just tells there are 4 of them. I need it to select the last A.
 
Upvote 0
I don't see why you need to select the cell (selecting is seldom necessary) but try like this

Code:
Sub test()
Dim s As Variant, LR As Long
s = "a"
LR = Columns("A").Find(What:=s, SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("A" & LR).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

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