Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
hsg hsg is offline
external usenet poster
 
Posts: 40
Default Select a range

My worksheet has ROW 1 as header, and the data is variable.
Sometimes it is from A2:H10040, or sometimes it may be from A2:H9400.
The rows vary but last column is always H.

I wish to perform certain sorting, or text trimming etc based on certain
values,
which I can do using Macros.

But how can I select the range before running the macros everytime I open
the file,
as the data size varies in rows. Scrolling down manually and selecting is
difficult as Last data row varies in range A9000 to A11000 or so.

How can I get a macro which will upon running will select the entire range
and will
give a name to it , say "myrange".

Pl help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Select a range


One of the many ways:

This will select the used range except row no.1:
Dim myRange As Range
With Worksheets("Sheet1").UsedRange
Set myRange = .Range(Cells(2, 1), Cells(.Rows.Count,
..Columns.Count))
End With

If you want to select row no. 1 also then its as simple
as:
Set myRange = Worksheets("Sheet1").UsedRange

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select a range

Hi Sharad,

Unless "Sheet1" is the active sheet, I think that the line

Set myRange = .Range(Cells(2, 1), Cells(.Rows.Count,
Columns.Count))


will cause an error and should read:

Set myRange _
= .Range(.Cells(2, 1), .Cells(.Rows.Count, .Columns.Count))

(dot added before each instance of Cells and before Columns.Count)

---
Regards,
Norman



"Sharad" wrote in message
...

One of the many ways:

This will select the used range except row no.1:
Dim myRange As Range
With Worksheets("Sheet1").UsedRange
Set myRange = .Range(Cells(2, 1), Cells(.Rows.Count,
Columns.Count))
End With

If you want to select row no. 1 also then its as simple
as:
Set myRange = Worksheets("Sheet1").UsedRange

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Select a range

Oh, yes, I realize that I forgot the 'dot'.
Thanks.

Sharad

"Norman Jones" wrote in message
...
Hi Sharad,

Unless "Sheet1" is the active sheet, I think that the line

Set myRange = .Range(Cells(2, 1), Cells(.Rows.Count,
Columns.Count))


will cause an error and should read:

Set myRange _
= .Range(.Cells(2, 1), .Cells(.Rows.Count, .Columns.Count))

(dot added before each instance of Cells and before Columns.Count)

---
Regards,
Norman



"Sharad" wrote in message
...

One of the many ways:

This will select the used range except row no.1:
Dim myRange As Range
With Worksheets("Sheet1").UsedRange
Set myRange = .Range(Cells(2, 1), Cells(.Rows.Count,
Columns.Count))
End With

If you want to select row no. 1 also then its as simple
as:
Set myRange = Worksheets("Sheet1").UsedRange

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





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
How do I select a range? Dan Excel Worksheet Functions 2 February 1st 09 07:49 PM
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
Select Sheet then Select Range Gee[_2_] Excel Programming 3 May 27th 04 10:10 PM
Select Range as far as..... universal[_24_] Excel Programming 4 January 15th 04 03:51 PM


All times are GMT +1. The time now is 01:03 AM.

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

About Us

"It's about Microsoft Excel"