Can't make two loops work

Solved/Closed
FRA - Sep 12, 2008 at 05:16 PM
 FRA - Oct 1, 2008 at 04:59 PM
Hello, here's my problem. I've got codes in column D that may show up more than once. On column A I've got a list of all available codes, and in column B the corresponding address. I want my macro to automatically replace each code in column D for its corresponding address.


Sub CambiarCodigos()
Dim iRow As Long
Dim jRow As Long
iRow = 3
jRow = 3
Do Until IsEmpty(Cells(iRow, "D"))
Do Until IsEmpty(Cells(jRow, "A")) 'works OK
Cells(iRow, "D") = Replace(Cells(iRow, "D"), Cells(jRow, "A"), Cells(jRow, "B")) 'works OK
jRow = jRow + 1 'works OK
Loop 'works OK
iRow = iRow + 1
Loop

End Sub

I really hope you can help!

1 reply

Ivan-hoe
Posts
433
Registration date
Saturday February 16, 2008
Status
Member
Last seen
October 17, 2008
109
Sep 13, 2008 at 01:58 AM
Hello FRA,
you're nearly there !
Move jRow = 3 immediately after Do Until IsEmpty(Cells(iRow, "D")) and it will work.
Ivan
Sub CambiarCodigos()
Dim iRow As Long, jRow As Long
iRow = 3
Do Until IsEmpty(Cells(iRow, "D"))
    jRow = 3
    Do Until IsEmpty(Cells(jRow, "A"))
etc.
0
Ivan, you're a genious. Thank you so very much!
0