VBA - Do Until Loop within Do Until Loop

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
790
Office Version
  1. 365
Platform
  1. Windows
I am such a VBA noob.

Code:
ML.Activate

Do Until Cells(ActiveCell.Row, "A") = ""


    tnam = Cells(ActiveCell.Row, "H").Value
    tno = Cells(ActiveCell.Row, "A").Value
    pup = Cells(ActiveCell.Row, "G").Value
    
    pp.Activate
    Range("A3").Activate
    
    Do Until Cells(ActiveCell.Row, "A") = ""
        If Cells(ActiveCell.Row, "C").Value = tnam And Left(Cells(ActiveCell.Row, "A").Value, 6) <> tno And InStr(1, Cells(ActiveCell.Row, "K").Value, pup) > 0 Then
        pptno = Cells(ActiveCell.Row, "A").Value
        ML.Activate
        Cells(ActiveCell.Row, "R").Value = pptno
        End If
        ActiveCell.Offset(1, 0).Activate
    Loop

ActiveCell.Offset(1, 0).Activate
Loop

In ML I need to set three variables, which are in H, A and G.

Then I go to PP (Price Panels) and loop all the way down until I find a match for all three variables.

Once this happens, I need it to hold whatever is in activecell on row A as a variable, then switch back to ML and paste that new variable in row R.

Once that happens, close the loop, go down a row in ML and re-open the loop.


I'm having trouble with getting it to come out of the loop, so the original loop can start again.

Do I put something like Do Until Cells = "" OR [condition to meet]?


I'm really confused, thanks.


EDIT: Lol, I've put in "Exit Do" after the "End If" in place of the Activecell offset, and it works. Leaving this up here to help others learn.
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Whoops, got it wrong again, this is the correct, working code:

Code:
ML.ActivateDo Until Cells(ActiveCell.Row, "A") = ""


    tnam = Cells(ActiveCell.Row, "H").Value
    tno = Cells(ActiveCell.Row, "A").Value
    pup = Cells(ActiveCell.Row, "G").Value
    
    pp.Activate
    Range("A3").Activate
    
    Do Until Cells(ActiveCell.Row, "A") = ""
        If Cells(ActiveCell.Row, "C").Value = tnam And Left(Cells(ActiveCell.Row, "A").Value, 6) <> tno And InStr(1, Cells(ActiveCell.Row, "K").Value, pup) > 0 Then
        pptno = Cells(ActiveCell.Row, "A").Value
        ML.Activate
        Cells(ActiveCell.Row, "R").Value = pptno
        Exit Do
        End If
        ActiveCell.Offset(1, 0).Activate
    Loop
ML.Activate


ActiveCell.Offset(1, 0).Activate
Loop
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top