How to specify a range in Excel macro

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hi,

How could I select a range in macro if I don't know how
many columns I have, meaning my columns is variable.

Example: Range("A1:A4").select

Need help.

TIA
Eric
 
Eric,.

Range("A1").Resize(1, Cells(1,
Columns.Count).End(xlToLeft).Column).Select


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
'select columns:
set rng = Range(cells(1,1),cells(1,256).End(xltoleft))
rng.Select

'select rows:
set rng = Range(cells(1,1),Cells(rows.count,1).End(xlup))
rng.Select
 
Eric,

Just noticed that you said variable columns, but your example showed
variable rows. If it should be rows, try

Range("A1").Resize(Cells(Rows.Count,"A").End(xlUp).Row,1).Select

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top