VBA to select several rows in named range

tttommy2

Board Regular
Joined
Oct 1, 2012
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi there

I hvae a named range "MyRange". I want to select rows 10 to 16. I'd have thought that

Range("MyRange").Rows(10:16).Select

would work. However it stops my Macro.

Any ideas please?

Thank you.

T
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This should do the trick for you

Code:
Sub selectrange()
Dim fr As Long
Dim lr As Long


fr = Range("MyRange").Row
lr = Range("MyRange").Cells(1, 1).Row + Range("MyRange").Rows.Count - 1


Worksheets("Sheet1").Rows(fr & ":" & lr).Select


End Sub
 
Upvote 0
Maybe this:
Code:
Range("MyRange").Rows("10:16").Select
 
Upvote 0
This works for me provided the sheet with named range 'MyRange' on it is the active sheet and that the named range has workbook scope.
Code:
Range("MyRange").Rows("10:16").Select
 
Upvote 0
Thank you Akuini and Norie. That works great.


How would I take this further using a variable for the Row numbers?

A1 = 10
B1 = 16
Code:
Dim i as long, j as long
i = Range("A1")
j= Range ("B1")

Range("MyRange").Rows("i:j").Select
Thanks
tttommy2


This works for me provided the sheet with named range 'MyRange' on it is the active sheet and that the named range has workbook scope.
Code:
Range("MyRange").Rows("10:16").Select
 
Last edited:
Upvote 0
To use variables try something like frank_AL suggested but replace fr and lr with i and j respectively.
Code:
Dim i as long, j as long

    i = Range("A1").Value
    j= Range ("B1").Value

    Range("MyRange").Rows(i & ":" & j).Select
 
Upvote 0
Solution
Thank you Norie and thank you frank_AL

tttommy2

To use variables try something like frank_AL suggested but replace fr and lr with i and j respectively.
Code:
Dim i as long, j as long

    i = Range("A1").Value
    j= Range ("B1").Value

    Range("MyRange").Rows(i & ":" & j).Select
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,762
Messages
6,132,578
Members
449,737
Latest member
naes

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