Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is there an easier way?

I need to referenece the following ranges, I'd rather not repeat the
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thank

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Is there an easier way?

I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.


You probably need to adjust the "5 To 17", but the following
should do it.

Dim iCt As Integer
Dim c as Range

For iCt = 5 To 17 Step 3
For Each c In Sheets("Sheet1").Range(Cells(11, iCt), Cells(125, iCt +
2))
'run code Next c
Next iCt

HTH,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is there an easier way?

Thanks Guys they both worked!

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

hotherps < wrote:
Thanks Guys they both worked!!


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

To do what??? They didn't work for me.

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

Did you test this before posting?

Alan Beban

merjet wrote:

I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.



You probably need to adjust the "5 To 17", but the following
should do it.

Dim iCt As Integer
Dim c as Range

For iCt = 5 To 17 Step 3
For Each c In Sheets("Sheet1").Range(Cells(11, iCt), Cells(125, iCt +
2))
'run code Next c
Next iCt

HTH,
Merjet




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is there an easier way?


For Each Cell in Un
ion(range("G11:H125"),range("I11:K125"),range("L11 :N125"))

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"hotherps " wrote in message
...
I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thanks


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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

Bob Phillips wrote:

For Each Cell in Un
ion(range("G11:H125"),range("I11:K125"),range("L11 :N125"))

This isn't any different from

For Each Cell in Range("G11:N125")

and it assumes that the code is the same for of the three ranges.

Alan Beban
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Is there an easier way?

See if this helps. 7 is col G . Change the 12 for your last column desired.

Sub runranges()
For i = 7 To 12 Step 2
For Each c In Range(Cells(11, i), Cells(15, i + 1))
MsgBox c.Address 'your code
Next c
Next i
End Sub
--
Don Guillett
SalesAid Software

"hotherps " wrote in message
...
I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thanks


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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

Don Guillett wrote:

See if this helps. 7 is col G . Change the 12 for your last column desired.

Sub runranges()
For i = 7 To 12 Step 2
For Each c In Range(Cells(11, i), Cells(15, i + 1))
MsgBox c.Address 'your code
Next c
Next i
End Sub

Did you test the code before posting? It operates on ranges G:H, I:J
(instead of I:K) and K:L (instead of L:N).

Alan Beban
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Is there an easier way?

I looked at his FIRST range which referenced g:H
so it should be step 3 and i+2 for every third column
but the op could have figured that out.
"It's the thought that counts" <G

--
Don Guillett
SalesAid Software

"Alan Beban" wrote in message
...
Don Guillett wrote:

See if this helps. 7 is col G . Change the 12 for your last column

desired.

Sub runranges()
For i = 7 To 12 Step 2
For Each c In Range(Cells(11, i), Cells(15, i + 1))
MsgBox c.Address 'your code
Next c
Next i
End Sub

Did you test the code before posting? It operates on ranges G:H, I:J
(instead of I:K) and K:L (instead of L:N).

Alan Beban





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

Don Guillett wrote:

I looked at his FIRST range which referenced g:H
so it should be step 3 and i+2 for every third column
but the op could have figured that out.
"It's the thought that counts" <G

Well, that doesn't get what the OP asked for either, so I'm not sure
what you're suggesting he could have figured out.

The OP indicated that "the range moves over three columns at a time,
like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc."

That's incoherent; G11:H125 to I11:K125 is *not* "moving over three
columns." And Don Guillett's revised code doesn't track with G:H, I:K,
and L:N, but with G:I, J:L, and M:O.

If the OP cares to clarify, I'll be happy to provide code.

Alan Beban
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

hotherps < wrote:

I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thanks


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

Moving from "G11:H125" to "Ill:K125" is *not* "moving over three columns
at a time".

Alan Beban
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is there an easier way?

glad to see such a positive approach!

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Alan Beban" wrote in message
...
hotherps < wrote:

I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thanks


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

Moving from "G11:H125" to "Ill:K125" is *not* "moving over three columns
at a time".

Alan Beban



  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Is there an easier way?

hotherps < wrote:

I need to referenece the following ranges, I'd rather not repeat them
over, the range moves over three columns at a time, like this:

For Each CELL In range("G11:H125")
'run code
For Each CELL In range("I11:K125")
'run code
For Each CELL In range("L11:N125")
'run code
etc.

Thanks


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

Sub runranges()
Dim rng As Range, n As Long, iCt As Long, c As Range
Set rng = Sheets("Sheet1").Range("A1")
n = 13
For iCt = 7 To n Step 3
If iCt = 7 Then
For Each c In Range(rng(11, iCt), rng(15, iCt + 1))
Debug.Print c.Address 'your code
Next c
ElseIf iCt = 10 Then
iCt = iCt - 1
For Each c In Range(rng(11, iCt), rng(15, iCt + 2))
Debug.Print c.Address 'your code
Next c
Else
For Each c In Range(rng(11, iCt), rng(15, iCt + 2))
Debug.Print c.Address 'your code
Next c
End If
Next iCt
End Sub

Alan Beban
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
Is there an easier way? Bigpond Setting up and Configuration of Excel 2 September 17th 08 03:17 PM
Is there an easier way... George[_4_] Excel Discussion (Misc queries) 1 August 28th 08 12:44 AM
There's Got to be an Easier Way Sprint54 Excel Discussion (Misc queries) 7 February 9th 06 12:06 AM
Is there an easier way? wmaughan Excel Discussion (Misc queries) 5 December 27th 05 10:56 PM
Easier Way? scott45 Excel Worksheet Functions 2 October 12th 05 04:55 AM


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