Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do I use a macro to select a range?

Dim sStr as String
Dim rng as Range, rng1 as Range
Dim rng2 as Range

sStr ="GJ"
Set rng = Columns(2).Find(What:=sStr, _
After:=Range("B1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set rng1 = Columns(2).Find(What:=sStr, _
After:=Range("B1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)

If not rng is nothing then
set rng2 = Range(rng,rng1)

if rng2.count < 1 then
rng2.Resize(,5).Sort Key1:=rng1.offset(0,1), Header:=xlNo
end if
End if


--
Regards,
Tom Ogilvy




"CBS" wrote in message
...
Excel 2000

I have a sorted list 5 columns wide. Column B has the value GJ in the
middle group of rows. The number of rows changes each month; the starting
row number with GJ changes each month as does the number of rows that
contain GJ. The middle group always has GJ in column B.

How can I write a macro that finds all the "GJ" rows and then sorts them
by
column C?

When I manually do this, I find the first GJ row, hold down the shift key
to
anchor the curser, then scroll down to the last row that has GJ, then
arrow
right to the 5th column. I haven't been able to duplicate this action
using
a macro.



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 range in macro Chris Excel Discussion (Misc queries) 1 February 19th 10 01:33 PM
How do I select a range using a macro? brettopp Excel Discussion (Misc queries) 3 November 8th 06 11:40 PM
Using macro to select a range Rob Excel Worksheet Functions 3 November 6th 06 08:31 PM
Range Select Macro Archie[_4_] Excel Programming 4 January 25th 06 08:57 PM
When you select a range with a macro Patrick[_6_] Excel Programming 2 December 2nd 03 08:26 AM


All times are GMT +1. The time now is 08:06 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"