VBA to select several rows in named range

tttommy2

Board Regular
Joined
Oct 1, 2012
Messages
55
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,119
Messages
6,128,947
Members
449,480
Latest member
yesitisasport

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