LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Nested Do Until Loop

I have a static array, AI2:AI37 that holds a list of department numbers that
I compare to another column of department numbers. The code below checks to
see if the department in cell AI42 matches the deparment in cell AI2. If it
does, change the value to 'MATCH TO DEPARTMENT' and move the the next cell
and compare to AI2. If no match, move to the next cell and compare to cell
AI2.

Sub DeptCompare()
Range("AI42").Select

Do Until IsEmpty(ActiveCell)
If ActiveCell = Range("AI2") Then
ActiveCell = "MATCH TO DEPARTMENT"
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Loop.
End Sub

This portion works fine. What I want to do is nest this loop in another
loop that moves down by one cell in the static array. I would replace
Range("AI2") with Range("AI3"). This pattern would continue until the code
encounters an empty cell.

Something like this

Sub DeptCompare()

Do Until (The code encounters an empty cell in the static array)

'Selects the first cell in the department list being compared to the
array.
Range("AI42").Select

'Loop throught the departement list being compared to the array
Do Until IsEmpty(ActiveCell)
If ActiveCell = Range("AI2") Then
ActiveCell = "MATCH TO DEPARTMENT"
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Loop

Move down 1 row to the next cell in the static array
Loop

End Sub

Thoughts?

Thanks in advance!
PJ
 
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
Nested loop [email protected] Excel Worksheet Functions 1 April 5th 07 12:50 AM
Nested Loop JMay Excel Programming 4 December 17th 06 11:19 PM
Nested loop order? jclark419[_4_] Excel Programming 2 July 29th 05 07:41 PM
Nested Loop Frank Kabel Excel Programming 6 September 12th 04 02:41 AM
Nested loop with ranking jp Excel Programming 2 October 2nd 03 03:28 PM


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