select a range w/in a range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have a maro w/ a named range from which I need to select 2 Nonadjacent
rows based on variables but can't seem to get the code right. I need to
select row$1, col_x and row_y, col_x of named_rng_z.

any help w/ the syntax would be appriciated

Zb Kornecki
 
Sub AAA()
Dim row1 As Long, row_y As Long
Dim col_x As Long
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
row1 = 3
row_y = 7
col_x = 2
Set rng1 = Range("named_rng_x")
Set rng2 = rng1(row1, col_x)
Set rng3 = rng1(row_y, col_x)
rng1.Parent.Select
Union(rng2, rng3).Select
End Sub
 
Zb Kornecki said:
Hi I have a maro w/ a named range from which I need to select 2
Nonadjacent
rows based on variables but can't seem to get the code right. I need to
select row$1, col_x and row_y, col_x of named_rng_z.

any help w/ the syntax would be appriciated

Zb Kornecki

Checkout the 'Union'-method, Zb.

Dim r As Range
Set r = Application.Union( _
ActiveSheet.Range("A1:E1"), _
ActiveSheet.Range("A4:E4"))
r.Select
 
Thanks Tom I follow what you're showing here except the Lines:
Set rng2 = rng1(row1, col_x)
Set rng3 = rng1(row_y, col_x)

this seems to Set the range to only one cell. How would I specify a ange of
cells?

thanks for your time
Zb
 
Sub AAA()
Dim row1 As Long, row_y As Long
Dim col_x As Long
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
row1 = 3
row_y = 7
col_x = 2
Set rng1 = Range("named_rng_x")
Set rng2 = rng1.Rows(row1)
Set rng3 = rng1.Rows(row_y)
rng1.Parent.Select
Union(rng2, rng3).Select
End Sub
 
Perfect thanks

Tom Ogilvy said:
Sub AAA()
Dim row1 As Long, row_y As Long
Dim col_x As Long
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
row1 = 3
row_y = 7
col_x = 2
Set rng1 = Range("named_rng_x")
Set rng2 = rng1.Rows(row1)
Set rng3 = rng1.Rows(row_y)
rng1.Parent.Select
Union(rng2, rng3).Select
End Sub
 
Thanks w/ your and Tom's Idea I got it to work perfect using Union method. I
just saved myself several hours a month writing out lists by hand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top