VBA HELP - Find Last Row of first range and not the range below - Excel 2013

magnum5az

New Member
Joined
Jun 21, 2017
Messages
16
Hi Guys,

I have a code that updates my named range "GrandTotal" which stores my Subtotal row from a Main Sheet. The Main sheet has two ranges of data, the main range A6:H144 which updates each day, and a lower data range A146:H152.

I am trying to have the code for Last row only look in the first range, similar to Starting from cell A6 and doing a CTRL+Shift+Down but not able to get it right.

Here is my code

Code:
Sub UpdateSub()

Dim LR As Long
Dim ws As Worksheet

Set ws = Sheets("NOI - Combined Property")

LR = ws.Range("A" & Rows.Count).End(xlDown).Row

Application.ScreenUpdating = False

ws.Activate
    With ActiveWorkbook.Names("Grandtotal")
        .Name = "Grandtotal"
        .RefersToR1C1 = "='NOI - Combined Property'!R" & LR & ""
        .Comment = ""
    
    End With

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hello,

isn;t it just a case of changing

Code:
LR = ws.Range("A" & Rows.Count).End(xlDown).Row

to

Code:
LR = ws.Range("A6").End(xlDown).Row

or am i missing something? i.e. blank cells?
 
Upvote 0
Assuming there are no empty cells between A6 and the "last" row of your upper range, try:
Code:
LR = ws.Range("A6").End(xlDown).Row
 
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