Do while loop

njones3

New Member
Joined
Apr 25, 2019
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I am hoping someone can help, I am trying to add a 'do while' type loop into some existing code. The current code makes manual changes to my data dump but it can only do one row at a time. Sometimes there are a large amount of rows which all need the same adjustment made to them so i need the loop to repeat the process until it has modified every relevant line of my data.

The section of existing code is below:
Code:
    If AdjustmentsArray(i, 1) = "Renewals (ESS Status)" Then
                    CheckColumn1 = Cells.Find(What:="MPAN", after:=Cells(1, 1), lookat:=xlWhole, searchorder:=xlByRows, MatchCase:=True).Column
                    CheckColumn2 = Cells.Find(What:="Contract ID", after:=Cells(1, 1), lookat:=xlWhole, searchorder:=xlByRows, MatchCase:=True).Column
                    CheckColumn3 = Cells.Find(What:="MPID", after:=Cells(1, 1), lookat:=xlWhole, searchorder:=xlByRows, MatchCase:=True).Column
                    CheckIterations = Application.CountIf(Columns(CheckColumn1), AdjustmentsArray(i, 2))
                    j = 1
                    CheckRow = 1
                    Set RangeFind = Cells.Find(What:=AdjustmentsArray(i, 2), after:=Cells(CheckRow, CheckColumn1), lookat:=xlWhole, searchorder:=xlByColumns)
                    If Not RangeFind Is Nothing Then
                        For j = 1 To CheckIterations
                            CheckRow = Cells.Find(What:=AdjustmentsArray(i, 2), after:=Cells(CheckRow, CheckColumn1), lookat:=xlWhole, searchorder:=xlByColumns).Row
                            If Cells(CheckRow, CheckColumn2) = AdjustmentsArray(i, 3) And Cells(CheckRow, CheckColumn3) = AdjustmentsArray(i, 5) Then ChooseRow = CheckRow
                        Next j
                        If ChooseRow = 0 Then Sheets("Manual Adjustments").Cells(i + FindRow(19), FindColumn(19)) = "Record not found"
                    Else
                        Sheets("Manual Adjustments").Cells(i + FindRow(19), FindColumn(19)) = "Record not found"
                    End If
                Else
Ideally it would look at column B and if there is a 'yes' in the box it would repeat the loop until all lines have been updated.

Thanks in advance,

Nathan
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
something like this:
Code:
Dim rng As Range, wsh As Worksheet, cc As Range
Set wsh = ThisWorkbook.Worksheets("[COLOR=#ff0000]sheet1[/COLOR]")
Set rng = Intersect(wsh.UsedRange, wsh.Range("B:B"))
For Each cc In rng
    If cc.Value = "yes" Then
        '.................. here you do what you need to do .......................
    End If
Next cc
Set rng = Nothing
Set cc = Nothing
Set wsh = Nothing
cc will be each cell in column B with yes in it when your code runs - so you can refer to it as range.
set the name in red to your sheet name. You will also probably have to make some adjustments to your code.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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