Working with a range within a range ?

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

Guest

I am trying to assing a sub range within a larger range of cells on a
worksheet.
I would like to be able to assign this smaller sub range within the larger
range of cells on my worksheet by just designating wich column within the
larger range should be used for the smaller range and the rest of the
paramiters such as number of rows for the smaller range should be taken from
the range paramiters of the larger range.

Set LRange = Worksheets("Sheet1").Range("A1:D10")

Set SRange = Range(LRange.Columns(1)) <-- This works but only gives me a
range of "A1" I need it to be "A1:A10"

anyone ????

Thanks again
Dan Thompson
 
Set LRange = Worksheets("Sheet1").Range("A1:D10")

Set SRange = LRange.Columns(1)

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
You can use the intersect function which gives you the intersection of two
ranges.

Sub SubRange()
Dim rngLarge As Range
Dim rngSmall As Range

Set rngLarge = Sheet1.Range("A1:D10")

Set rngSmall = Intersect(Sheet1.Range("A1").EntireColumn, rngLarge)
rngSmall.Select

End Sub

You can modify this as is necessary. I made some specific references.

HTH
 
Thanks Jim your solution worked for what I need to do.

Thanks for your input too Bob. However usning your method does sort of work
but it only gives you a row count of 1 for the new sub range. This is the same
problem I was already having. Thanks anyway
 
For me, the following displays A1:D10 and C1:C10

Sub Test()
Dim Rng1 As Range
Dim Rng2 As Range
Set Rng1 = Range("A1:D10")
Set Rng2 = Rng1.Columns(3)
Debug.Print Rng1.Address, Rng2.Address
End Sub

OTOH, this statement produces an error.

Debug.Print Range(Rng1.Columns(3)).Address

probably because Range wants 2 references rather than just 1.
 

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