Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Select multiple ranges of data

Hello:

I'm trying to tell Excel to select multiple columns, but a want only
the cells in the data range selected. If I use the following it
selects the entire column -

Range("Z:Z,AP:AP").Select

which is close but I want it to select only as far as the last row of
data.


What I am trying to get is -

Last = LRow(WS)
Range("Z3:Z" & Last,"AP3:AP" & Last).Select

But it selects everything as if I had entered
Range("Z3:AP"&Last).Select


Any help is greatly appreciated. I guess I don't quite understand how
the Range function works.



Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Select multiple ranges of data

Perhaps:

Intersect(ActiveSheet.UsedRange,Range("Z:Z,AP:AP") ).Select
--
Gary''s Student - gsnu2007j


" wrote:

Hello:

I'm trying to tell Excel to select multiple columns, but a want only
the cells in the data range selected. If I use the following it
selects the entire column -

Range("Z:Z,AP:AP").Select

which is close but I want it to select only as far as the last row of
data.


What I am trying to get is -

Last = LRow(WS)
Range("Z3:Z" & Last,"AP3:AP" & Last).Select

But it selects everything as if I had entered
Range("Z3:AP"&Last).Select


Any help is greatly appreciated. I guess I don't quite understand how
the Range function works.



Steven

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Select multiple ranges of data

On Jul 31, 11:44*am, Gary''s Student
wrote:
Perhaps:

Intersect(ActiveSheet.UsedRange,Range("Z:Z,AP:AP") ).Select
--
Gary''s Student - gsnu2007j

" wrote:
Hello:


I'm trying to tell Excel to select multiple columns, but a want only
the cells in the data range selected. If I use the following it
selects the entire column -


Range("Z:Z,AP:AP").Select


which is close but I want it to select only as far as the last row of
data.


What I am trying to get is -


Last = LRow(WS)
Range("Z3:Z" & Last,"AP3:AP" & Last).Select


But it selects everything as if I had entered
Range("Z3:AP"&Last).Select


Any help is greatly appreciated. I guess I don't quite understand how
the Range function works.


Steven


Hmmmm, it does select the range limits quite nicely, but I am now
getting a 424 error, Object required. This is the code that I am
applying it to -

For Each MyCell In Intersect(ActiveSheet.UsedRange,
Range("Z:Z,AP:AP")).Select
MyCell.Formula = MyCell.Value & " " _
& MyCell.Offset(0, 1).Value & " " _
& MyCell.Offset(0, 2).Value & " " _
& MyCell.Offset(0, 3).Value & " " _
& MyCell.Offset(0, 4).Value
MyCell.Formula = LTrim(MyCell.Formula)
MyCell.Formula = RTrim(MyCell.Formula)
Next

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Select multiple ranges of data

Couple of comments:

1. You don't need the Select in the For statement:
For Each MyCell In Intersect(ActiveSheet.UsedRange, Range("Z:Z,AP:AP"))

2. Make sure you have Dim'ed MyCell as a Range

3. Make sure the equals sign is in the formula:
MyCell.Formula="1+2" will not work as a formula
MyCell.Formula="=1+2" will work as a formula


--
Gary''s Student - gsnu200797


" wrote:

On Jul 31, 11:44 am, Gary''s Student
wrote:
Perhaps:

Intersect(ActiveSheet.UsedRange,Range("Z:Z,AP:AP") ).Select
--
Gary''s Student - gsnu2007j

" wrote:
Hello:


I'm trying to tell Excel to select multiple columns, but a want only
the cells in the data range selected. If I use the following it
selects the entire column -


Range("Z:Z,AP:AP").Select


which is close but I want it to select only as far as the last row of
data.


What I am trying to get is -


Last = LRow(WS)
Range("Z3:Z" & Last,"AP3:AP" & Last).Select


But it selects everything as if I had entered
Range("Z3:AP"&Last).Select


Any help is greatly appreciated. I guess I don't quite understand how
the Range function works.


Steven


Hmmmm, it does select the range limits quite nicely, but I am now
getting a 424 error, Object required. This is the code that I am
applying it to -

For Each MyCell In Intersect(ActiveSheet.UsedRange,
Range("Z:Z,AP:AP")).Select
MyCell.Formula = MyCell.Value & " " _
& MyCell.Offset(0, 1).Value & " " _
& MyCell.Offset(0, 2).Value & " " _
& MyCell.Offset(0, 3).Value & " " _
& MyCell.Offset(0, 4).Value
MyCell.Formula = LTrim(MyCell.Formula)
MyCell.Formula = RTrim(MyCell.Formula)
Next


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Select multiple ranges of data

On Jul 31, 12:16*pm, Gary''s Student
wrote:
Couple of comments:

1. You don't need the Select in the For statement:
For Each MyCell In Intersect(ActiveSheet.UsedRange, Range("Z:Z,AP:AP"))

2. Make sure you have Dim'ed MyCell as a Range

3. Make sure the equals sign is in the formula:
MyCell.Formula="1+2" will not work as a formula
MyCell.Formula="=1+2" will work as a formula

--
Gary''s Student - gsnu200797

" wrote:
On Jul 31, 11:44 am, Gary''s Student
wrote:
Perhaps:


Intersect(ActiveSheet.UsedRange,Range("Z:Z,AP:AP") ).Select
--
Gary''s Student - gsnu2007j


" wrote:
Hello:


I'm trying to tell Excel to select multiple columns, but a want only
the cells in the data range selected. If I use the following it
selects the entire column -


Range("Z:Z,AP:AP").Select


which is close but I want it to select only as far as the last row of
data.


What I am trying to get is -


Last = LRow(WS)
Range("Z3:Z" & Last,"AP3:AP" & Last).Select


But it selects everything as if I had entered
Range("Z3:AP"&Last).Select


Any help is greatly appreciated. I guess I don't quite understand how
the Range function works.


Steven


Hmmmm, it does select the range limits quite nicely, but I am now
getting a 424 error, Object required. This is the code that I am
applying it to -


* * * * For Each MyCell In Intersect(ActiveSheet.UsedRange,
Range("Z:Z,AP:AP")).Select
* * * * * * * * * * * * * * MyCell.Formula = MyCell.Value & " " _
* * * * * * * * * * * * * * * * *& MyCell.Offset(0, 1).Value & " " _
* * * * * * * * * * * * * * * * *& MyCell.Offset(0, 2).Value & " " _
* * * * * * * * * * * * * * * * *& MyCell.Offset(0, 3).Value & " " _
* * * * * * * * * * * * * * * * *& MyCell.Offset(0, 4).Value
* * * * * * * * * * * * * * MyCell.Formula = LTrim(MyCell.Formula)
* * * * * * * * * * * * * * MyCell.Formula = RTrim(MyCell.Formula)
* * * * Next


Thanks Gary, I think it was probably the select, the formulas worked
fine but I was concerned about the macro running over more rows than
necessary. The worksheet I am working on has 656 rows of data but was
running on all 65000+ with the entire column selected.

This is great.
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
Select Multiple Ranges with Certain Data to Print RyanH Excel Programming 2 November 8th 07 06:19 PM
select multiple ranges in formula dschanak Excel Discussion (Misc queries) 2 June 6th 07 04:53 PM
How to select multiple ranges in Excel with vbs Stefan Mueller Excel Programming 9 May 4th 05 04:55 PM
in charting, how do i select data ranges from multiple sheets, sa. michael Charts and Charting in Excel 1 March 6th 05 03:01 PM
select multiple cell ranges in "sumif" formula? Hitcoach Excel Worksheet Functions 1 January 16th 05 11:07 PM


All times are GMT +1. The time now is 10:49 PM.

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"