Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop through columns

I have some code that runs through the following range:

G9:CX300

I would like to loop through 8 columns at a time instead of the whol
range. i.e.

G9:N300
O9:V300

etc

Thank

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default loop through columns

Try this, it sets a range irng in blocks of 8 columns

Sub StepLoop()
Dim irng As Range
Dim iloop As Integer
For iloop = 7 To 102 Step 8
Set irng = Range(Cells(9, iloop), Cells(300, iloop + 7))
' act on your range irng in here
Next iloop
End Sub

Cheers
Nigel

"hotherps " wrote in message
...
I have some code that runs through the following range:

G9:CX300

I would like to loop through 8 columns at a time instead of the whole
range. i.e.

G9:N300
O9:V300

etc

Thanks


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default loop through columns

Hi
and what are you trying to do with these ranges?. You may
post the relevant part of your existing code

-----Original Message-----
I have some code that runs through the following range:

G9:CX300

I would like to loop through 8 columns at a time instead

of the whole
range. i.e.

G9:N300
O9:V300

etc

Thanks


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

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop through columns

Thanks Guys, here is the code:

Dim c 'don't know as what
Dim i As Integer
Dim rng As Range

On Error Resume Next
With Sheets("MonTest")
.Range("G11:CX125").ClearContents
End With
Range("G11:CX125").Formula
"=IF(AND(g$9=$B11,g$9<=$C11),""..."","""")"
Range("G11:CX125").Value = Range("G11:CX125").Value


For Each Cell In Range("G11:CX125")
c = Array(7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)
For i = 0 To 11
If Cells(356, c(i)).Value = Cells(305, c(i)) And Cell.Value "" _
And Cells(Cell.Row, c(i) + 97) = "x" Then _
Cell.Value = Cells(9, c(i) + 97)
Next i
Next


What it should do (not currently working) is to determine if 356 30
and + 97 = "x", and the cell value = ... If so place the the text tha
is in the corresponding cell. (One cell above)

Do this 8 columns at a time from D11 to CX125

Thanks
Ji

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop through columns

Nigel,

Is this you way you suggested to set it up?

Dim c
Dim i As Integer
Dim rng As Range
Dim irng As Range
Dim iloop As Integer

On Error Resume Next
With Sheets("MonTest")
.Range("G11:CX125").ClearContents
End With
Range("G11:CX125").Formula
"=IF(AND(g$9=$B11,g$9<=$C11),""..."","""")"
Range("G11:CX125").Value = Range("G11:CX125").Value

'For Each Cell In Range("G11:CX125")

For iloop = 7 To 102 Step 8
Set irng = Range(Cells(9, iloop), Cells(300, iloop + 7))
' act on your range irng in here

c = Array(20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10)
For i = 0 To 11
If Cells(356, c(i)).Value = Cells(305, c(i)) And Cell.Value "" _
And Cells(Cell.Row, c(i) + 97) = "x" Then _
Cell.Value = Cells(9, c(i) + 97)
Next i
'Next
Next iloop

Does not seem to work
thank

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default loop through columns

"Does not seem to work"???? What happens?

Alan Beban

hotherps < wrote:
Nigel,

Is this you way you suggested to set it up?

Dim c
Dim i As Integer
Dim rng As Range
Dim irng As Range
Dim iloop As Integer

On Error Resume Next
With Sheets("MonTest")
Range("G11:CX125").ClearContents
End With
Range("G11:CX125").Formula =
"=IF(AND(g$9=$B11,g$9<=$C11),""..."","""")"
Range("G11:CX125").Value = Range("G11:CX125").Value

'For Each Cell In Range("G11:CX125")

For iloop = 7 To 102 Step 8
Set irng = Range(Cells(9, iloop), Cells(300, iloop + 7))
' act on your range irng in here

c = Array(20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10)
For i = 0 To 11
If Cells(356, c(i)).Value = Cells(305, c(i)) And Cell.Value "" _
And Cells(Cell.Row, c(i) + 97) = "x" Then _
Cell.Value = Cells(9, c(i) + 97)
Next i
'Next
Next iloop

Does not seem to work
thanks


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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop through columns

The code only runs in the original for next range, i needed it to ru
again on the next 8 columns to the right, and so on. So it would b
like:

For Each cell In Range("G11:N125")
then O11:V125
AD11 etc

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

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
loop over columns kizzie Excel Discussion (Misc queries) 4 August 10th 05 01:31 PM
Loop 20 columns Help! Michael168[_106_] Excel Programming 2 July 2nd 04 12:26 PM
Excel VBA - loop columns named AA, AB..etc Tobias[_2_] Excel Programming 3 April 19th 04 01:26 PM
Loop through ranges columns hotherps[_32_] Excel Programming 1 February 26th 04 10:52 PM
How do I delete rows and columns in With With End Loop? Bob Benjamin Excel Programming 3 November 16th 03 12:26 AM


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

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"