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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to specify a range in Excel macro

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)

"Eric" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to specify a range in Excel macro

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)

"Bob Phillips" wrote in message
...
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)

"Eric" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to specify a range in Excel macro

you could try something like

Range("A:A").select

should wor

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to specify a range in Excel macro

'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

--
Regards,
Tom Ogilvy

"Eric" wrote in message
...
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





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
Need help writing Excel macro when range changes AT Excel Worksheet Functions 1 December 13th 07 03:09 AM
macro to copy from excel range to word doc mopgcw Excel Discussion (Misc queries) 1 August 20th 07 07:54 PM
Help with Dynamically changing Range in Excel Macro runsrealfast Excel Discussion (Misc queries) 4 July 16th 07 10:44 PM
How do I set up a formula with a changing range in an excel macro cinvic Excel Discussion (Misc queries) 2 April 4th 06 10:39 PM
Using a macro to set a range name in EXCEL Eric Tepen Excel Programming 2 January 25th 04 02:19 AM


All times are GMT +1. The time now is 04:30 PM.

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

About Us

"It's about Microsoft Excel"