End(xlUp) problem, can't figure this out, please take a look

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
Code:
    Set c = ThisWorkbook.Sheets("List")
    d = c.Range("D" & Range("D" & Rows.Count).End(xlUp).Row).Row
    If d < 2 Then d = 2
 
    Set g = ThisWorkbook.Sheets("Sum")
    h = g.Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Row
 
[FONT=Times New Roman]     MsgBox “Sheet name = ” & g.Name & “, “ & “Last Row = “ & h[/FONT]

This code is not working properly.

This should return the last blank row in column A of sheet "Sum".
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Instead, it’s returning the last blank row in column A of the active sheet.

I know this because I've changed the active sheet a bunch of times. Every time I do, the code spits out the last row of the active sheet, while "g.Name" returns the name of sheet "Sum".

Any ideas about this weird issue?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
    Set c = ThisWorkbook.Sheets("List")
    d = c.Range("D" & Range("D" & Rows.Count).End(xlUp).Row).Row
    If d < 2 Then d = 2
 
    Set g = ThisWorkbook.Sheets("Sum")
    h = g.Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Row
 
[FONT=Times New Roman]     MsgBox “Sheet name = ” & g.Name & “, “ & “Last Row = “ & h[/FONT]

This code is not working properly.

This should return the last blank row in column A of sheet "Sum".
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Instead, it’s returning the last blank row in column A of the active sheet.

I know this because I've changed the active sheet a bunch of times. Every time I do, the code spits out the last row of the active sheet, while "g.Name" returns the name of sheet "Sum".

Any ideas about this weird issue?

I think you need to include g. in the rows bit, otherwise rows.count only returns the rows of the activesheet. eg

h = g.Range("A" & g.Range("A" & g.Rows.Count).End(xlUp).Row).Row

regards

Bolo
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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