Select range using End(xlUp).Row + 1

H4rri

New Member
Joined
Oct 28, 2011
Messages
21
I'm pulling my hair (what's left of it) out over this stupid little idea!

I'm trying to add a dataset to the last available row, all works fine. Then I want to select the row and place a border around it.

I can do it statically with:

Code:
ActiveSheet.Range("C1:F4").Select

But it just won't do it dynamically with:

Code:
Dim ws, iRow
Set ws = Sheets("Sheet1")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
ActiveSheet.Range("A" & iRow & ":F" & iRow & ").Select

I can't see what's wrong, any idea's? Obviously these are only the relevant code snippets, the rest is mundane and working fine.


Steve
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Does this work?
Code:
Dim ws as Worksheet
Dim iRow as Long

Set ws = Sheets("Sheet1")
With ws
    .Select
    iRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
    .Range("A" & iRow & ":F" & iRow).Select
End With
 
Upvote 0
Hi Steve

You have an unnecessary & " in there:

Code:
ActiveSheet.Range("A" & iRow & ":F" & iRow).Select

However, please note it is rarely necessary to Select anything
 
Upvote 0

Forum statistics

Threads
1,212,098
Messages
6,105,952
Members
447,986
Latest member
dicklim39

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