Do while loop

njones3

New Member
Joined
Apr 25, 2019
Messages
9
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:

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,283
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.
 

Forum statistics

Threads
1,082,367
Messages
5,365,028
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top