Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default select a range w/in a range

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default select a range w/in a range

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

--
Regards,
Tom Ogilvy


"Zb Kornecki" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default select a range w/in a range


"Zb Kornecki" <zDOTkorneckiATcomcastDOTnet schreef in bericht
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default select a range w/in a range

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

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Zb Kornecki" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default select a range w/in a range

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


--
Regards,
Tom Ogilvy



"Zb Kornecki" <zDOTkorneckiATcomcastDOTnet wrote in message
...
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

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Zb Kornecki" wrote:

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default select a range w/in a range

Perfect thanks

"Tom Ogilvy" wrote:

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


--
Regards,
Tom Ogilvy



"Zb Kornecki" <zDOTkorneckiATcomcastDOTnet wrote in message
...
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

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Zb Kornecki" wrote:

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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default select a range w/in a range

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

"moon" wrote:


"Zb Kornecki" <zDOTkorneckiATcomcastDOTnet schreef in bericht
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA to select a range within a range. GoBow777 Excel Discussion (Misc queries) 3 September 13th 09 11:09 PM
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM


All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"