View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rowan Drummond[_3_] Rowan Drummond[_3_] is offline
external usenet poster
 
Posts: 414
Default Newbie Q: Range from two cells

Assuming the two variables you are refering to are defined as ranges
then maybe like this:

Sub test1()
Dim Cell1 As Range
Dim Cell2 As Range
Dim myRange As Range

Set Cell1 = Range("A10")
Set Cell2 = Range("A20")


Set myRange = Range(Cell1.Address & ":" & Cell2.Address)
Debug.Print myRange.Address

End Sub

Otherwise if you have variables representing row numbers then:

Sub test2()
Dim sRow As Long
Dim eRow As Long
Dim myRange As Range

sRow = 10
eRow = 20

Set myRange = Range(Cells(sRow, "A"), Cells(eRow, "A"))
Debug.Print myRange.Address

End Sub

Hope this helps
Rowan

Garry wrote:
Hi All:

I'm pretty familiar with Word VBA and am now blundering around Excel. A
few successes so far. I find the trickiest thing so far is adapting
myself from Word's range object to Excel's.

An elementary question. I have two variables, representing two cells in
the same column. What is the easy way to return a range = to all the
cells between (and including) the two? So far my untutored brain can
only think of a complicated statement involving offsets and resizes.


Oh.. if there are any traps-for-young-players a newbie should know, I'd
appreciate it.

Thanks for your time,
Garry