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 ranges

I have some code that runs down Rows 10-377, and it ranges in column
from K to R. The rows always stay the same but the columns need t
advance to the right. The way I have it now is repeating all of th
same code for new range.
I already have a for statement looks like this:

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "QAPK" Then
Set rng = cell 'y ??
Exit For
End If

next sub:
For i = 1 To 377
For Each cell In Rows(i).Columns("AI:AJ")
Set rng = Nothing
If cell.Value = "QAPK" Then
Set rng = cell 'y ??
Exit For

The only difference is the new column names.

How can I tell it to loop through multiple ranges without creating
new sub?

Thank

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop through ranges

Soory about that I only pasted a snippet of the code. Here is th
routine, it actually has multiple goals creating numeric assignment
for strings that match. My problem is on the line:

For Each cell In Rows(i).Columns("K:AA")

I need to be able to have this range change after an area has bee
completed. i.e.

K:AA AB:AS AT:BB etc until it reaches EU

I'm not sure how to expand or Loop the statement?

Thanks


Dim arr(100 To 144) As String
Dim arr1, num
Dim rng As Range, cell As Range
Dim i As Long, j As Long
arr1 = Array(125, 127, 129, 131, 133)

For Each cell In Range("K10:DB377")
'If cell.Value = "PPI" Then cell.Value = "PACK"
Next

Application.ScreenUpdating = False

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "QAPK" Then
Set rng = cell 'y ??
Exit For
End If
Next
If Not rng Is Nothing Then
For j = LBound(arr1) To UBound(arr1)
num = ""
If Len(Trim(arr(arr1(j)))) = 0 Then
num = arr1(j)
arr(num) = "QA"
Exit For
End If
Next
If num = "" Then num = "PK"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "QAPK" Then
cell.Value = "QA" & num
End If
Next
End If
Next

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "ICE" Then
Set rng = cell
Exit For
End If
Next
If Not rng Is Nothing Then
For j = 100 To 138 Step 2
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "IC"
Exit For
End If
Next
If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "ICE" Then
cell.Value = "IC" & num
End If
Next
End If
Next

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "PACK" Then
Set rng = cell
Exit For
End If
Next
If Not rng Is Nothing Then
For j = 100 To 144 Step 1
If InStr("119-135-137-139", Trim(Str(j))) Then GoTo skip
num = ""
If Len(Trim(arr(j))) = 0 Then
num = j
arr(num) = "PK"
Exit For
End If
skip: Next
If num = "" Then num = "PPI"
For Each cell In Range(rng, Cells(rng.Row, "AA"))
If cell.Value = "PACK" Then
cell.Value = "PK" & num
End If
Next
End If
Nex

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Loop through ranges

Very weird code, it don't do anything.

Why not try to record doing a find and replace, for each of your strings to get the code?


Regards Robert


"hotherps " wrote in message ...
I have some code that runs down Rows 10-377, and it ranges in columns
from K to R. The rows always stay the same but the columns need to
advance to the right. The way I have it now is repeating all of the
same code for new range.
I already have a for statement looks like this:

For i = 1 To 377
For Each cell In Rows(i).Columns("K:AA")
Set rng = Nothing
If cell.Value = "QAPK" Then
Set rng = cell 'y ??
Exit For
End If

next sub:
For i = 1 To 377
For Each cell In Rows(i).Columns("AI:AJ")
Set rng = Nothing
If cell.Value = "QAPK" Then
Set rng = cell 'y ??
Exit For

The only difference is the new column names.

How can I tell it to loop through multiple ranges without creating a
new sub?

Thanks


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



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004


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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
How to loop through all ranges in a worksheet Nanette[_2_] Excel Programming 6 January 12th 04 07:30 PM
loop to name ranges spence[_3_] Excel Programming 1 January 8th 04 05:16 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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