vba - last row in column

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,589
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I am trying to find the last non blank cell in a column. I have the following code - but get an application 1004 error on the line in bold.

the msgbox returns a valid address. "graph" is a valid sheet name and price_workbook exists.Any thoughts ? thanks

regards

Kaps



Rich (BB code):
Public Function last_non_blank_cell(cell_address As Range) As Long
MsgBox cell_address.Address
    last_non_blank_cell = price_workbook.Sheets("graph").Range(cell_address).End(xlDown).Row
End Function
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Here's one way: (finds last non-blank cell in column D)

Code:
Dim lngLastRow As Long
    lngLastRow = wsExperiments.Range("D65536").End(xlUp).Row
 
Upvote 0
It seems like your code wants to find next blank column since it does End(xlDown).
Keep in mind that End(direction) simulates the same action as pressing ctrl+direction in the spreadsheet.

Anyways, here is the code that may/may not help:
Rich (BB code):
Public Function last_non_blank_cell(cell_address As Range) As Long
MsgBox cell_address.Address
    last_non_blank_cell = price_workbook.Sheets("graph").Cells(Rows.count,cell_address.column).End(xlUp).Row
End Function
 
Upvote 0
Thanks Kpark91 - that stopped my error (no idea why it caused it though).
 
Upvote 0
Thanks Kpark91 - that stopped my error (no idea why it caused it though).

Because Range(...) expects a STRING like "A1"
But since cell_address is dimmed as a Range,
you fed it another range object.

For your original code to work you would want

last_non_blank_cell = price_workbook.Sheets("graph").Range(cell_address.Address).End(xlDown).Row
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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