Thread: variable range
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_5_] Bob Phillips[_5_] is offline
external usenet poster
 
Posts: 620
Default variable range

Jeff,

Range("A2:" & mylastcell)

--

HTH

Bob Phillips

"JEFF" wrote in message
...
Hi
Does anyone know how to put a variable into a range?

The range is a list in column A which is refreshed when
the workbook is opened.
This list is then loaded into a combobox on a form.

using the range notation
Range("x:y")
x is a constant of A2
and y is the variable mylastcell which has a maximum value
of A138 ie range("A2:A138")

However I only want to display the cells that have
something in them in the combobox, in order not to have
blank spaces at the bottom.

I'm able to return the address of the last cell with
something in it by using
mylastcell = Range("A2").End(xlDown).Address
(ROWABSOLUTE:=False)

However, having obtained a value for mylastcell, I'm
unable to put it into range notation
eg range("A2:mylastcell")

I need your help!