Find last cell in column and select a cell within a range combination

EngSantiago

New Member
Joined
Mar 19, 2014
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I need some guidance and how to improve VBA code. Currently, I'm using the following command to find a part number "PN" within a range (B2:C5000).
Code:
Worksheets("Data_Base").range("B2:C5000").Find(What:=PN).Select

The problem is that as the parts list gets bigger the formula wont find any PNs after row 5000. The scope is to always adjust the range by finding cell address of the last non-blank cell on column C.

Currently, I'm using the following to get the last cell address on column C.
Code:
lCol = 3lRow = Cells(Rows.Count, 3).End(xlUp).Row
FindLast = ActiveSheet.Cells(lRow, lCol).Address(False, False)

The part I'm having trouble with is getting the below command to select the cell that cointains the "PN" when I use FindLast on the command. I've tried the following but doesnt seem to be working.
Code:
Worksheets("Data_Base").range("B2:Findlast").Find(What:=PN).Select
Code:
Worksheets("Data_Base").range("B2:C2 & FindLast").Find(What:=PN).Select

Please advise.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try
Code:
Worksheets("Data_Base").Activate
LRow = Cells(Rows.Count, 3).End(xlUp).Row
Range("B2:C" & LRow).find(What:=PN).Select
 
Upvote 0
Try
Code:
Worksheets("Data_Base").Activate
LRow = Cells(Rows.Count, 3).End(xlUp).Row
Range("B2:C" & LRow).find(What:=PN).Select

Thanks for replying. Know I now what I was doing wrong. I was using
Code:
[COLOR=#574123]LRow = Cells(Rows.Count, 3).End(xlUp).Row[/COLOR]
on the Sub but then I was calling a Function FindPN(r As Integer) to find the part number. As soon as I plugged in
Code:
[COLOR=#574123]LRow = Cells(Rows.Count, 3).End(xlUp).Row[/COLOR]
in Function FindPN the code started working correctly.

Thanks again!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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