Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Need Help on Dynamic Range Selection

Hi All,

I need an urgent help with one of the macros I am working on

Say I am at the cell A2. I need to select the range A2:G3. When I try
to record macro for this, it reads

Range("A2").Select
Range("A2:G2").Select

The Problem is that I dont need the Alphabetic reference as I need to
repeat the step for every 3rd row (A5, A8, A11 etc )..I was trying to
use the RC reference but its not working.

Please help

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Need Help on Dynamic Range Selection

Try this

Sub RangeSelect()
Dim myRange As Range
Dim aWS As Worksheet

Set aWS = ActiveSheet

Set myRange = aWS.Range("A2")
Set myRange = myRange.Resize(2, 7)

Do While myRange.Row < aWS.Rows.Count - 4
Set myRange = myRange.Offset(3, 0)
Debug.Print myRange.Address

Loop

End Sub

BTW, you don't need to say it's URGENT here. If people can answer, they
will. This happened to be the first unanswered question I saw this morning.

HTH,
Barb Reinhardt

"anshu" wrote:

Hi All,

I need an urgent help with one of the macros I am working on

Say I am at the cell A2. I need to select the range A2:G3. When I try
to record macro for this, it reads

Range("A2").Select
Range("A2:G2").Select

The Problem is that I dont need the Alphabetic reference as I need to
repeat the step for every 3rd row (A5, A8, A11 etc )..I was trying to
use the RC reference but its not working.

Please help

Thanks in advance


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Need Help on Dynamic Range Selection

"anshu" skrev i en meddelelse
ups.com...
Hi All,

I need an urgent help with one of the macros I am working on

Say I am at the cell A2. I need to select the range A2:G3. When I try
to record macro for this, it reads

Range("A2").Select
Range("A2:G2").Select

The Problem is that I dont need the Alphabetic reference as I need to
repeat the step for every 3rd row (A5, A8, A11 etc )..I was trying to
use the RC reference but its not working.

Please help

Thanks in advance



Hi anshu

Here's one way:

Sub test()
'Leo Heuser, 11-7-2007
Dim CollectRange As Range
Dim Counter As Long

Set CollectRange = ActiveSheet.Range("A2:G2")

For Counter = 3 To 12 Step 3
Set CollectRange = _
Union(CollectRange, CollectRange.Offset(Counter, 0))
Next Counter

MsgBox CollectRange.Address

End Sub

--
Best regards
Leo Heuser

Followup to newsgroup only please.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Need Help on Dynamic Range Selection

Right click sheet tabview codeinsert this. Now when you select a2, a2:g3
will be selected, etc. But WHY select when it is usually not desirable. Tell
us more.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 And Target.Row Mod 3 = 2 Then
Target.Resize(2, 7).Select
End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"anshu" wrote in message
ups.com...
Hi All,

I need an urgent help with one of the macros I am working on

Say I am at the cell A2. I need to select the range A2:G3. When I try
to record macro for this, it reads

Range("A2").Select
Range("A2:G2").Select

The Problem is that I dont need the Alphabetic reference as I need to
repeat the step for every 3rd row (A5, A8, A11 etc )..I was trying to
use the RC reference but its not working.

Please help

Thanks in advance


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Need Help on Dynamic Range Selection

Thanks everyone for the replies...I could figure it out now...I
apologize for using the "Urgent" header...I was not aware of the
protocols here as I am brand new...:-) Thanks once again for the
codes. Though I could not understand any of the codes, I could somehow
make Leo Heuser's code work. Thanks to all other too!

Cheers,
Anshuman

On Jul 11, 9:08 pm, "Don Guillett" wrote:
Right click sheet tabview codeinsert this. Now when you select a2, a2:g3
will be selected, etc. But WHY select when it is usually not desirable. Tell
us more.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 And Target.Row Mod 3 = 2 Then
Target.Resize(2, 7).Select
End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"anshu" wrote in message

ups.com...

Hi All,


I need an urgent help with one of the macros I am working on


Say I am at the cell A2. I need to select the range A2:G3. When I try
to record macro for this, it reads


Range("A2").Select
Range("A2:G2").Select


The Problem is that I dont need the Alphabetic reference as I need to
repeat the step for every 3rd row (A5, A8, A11 etc )..I was trying to
use the RC reference but its not working.


Please help


Thanks in advance





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Need Help on Dynamic Range Selection

"anshu" skrev i en meddelelse
ups.com...
Thanks everyone for the replies...I could figure it out now...I
apologize for using the "Urgent" header...I was not aware of the
protocols here as I am brand new...:-) Thanks once again for the
codes. Though I could not understand any of the codes, I could somehow
make Leo Heuser's code work. Thanks to all other too!

Cheers,
Anshuman


You're welcome, Anshuman. Thanks for your feedback.

Regards
Leo Heuser


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
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
Dynamic Field Selection - Calculation Matt Cromer Excel Discussion (Misc queries) 1 August 21st 06 11:13 PM
dynamic selection of cells parthaemail New Users to Excel 1 April 25th 06 12:13 PM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Macro - Dynamic cell selection Chris Excel Discussion (Misc queries) 1 January 11th 06 01:48 PM


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