How can I have excel go down a list and check for certain conditions?

Viewed 27

This is code the internet and I came up with. Please could you tell me what I’m doing wrong? I keep getting an error that says “can’t use a loop without a do”

Sub additions ()

Range(“BI1”)  = “Comments”

Range(“V2”).Select

Do until IsEmpty(ActiveCell)


If (Range(ActiveCell) = “DM”) Then 
ActiveCell.Offset(0,39).Select
Range(ActiveCell) = “Developed Markets”
ActiveCell.Offset(1,-39).Select
End If

Loop

End Sub
1 Answers

Add String to One Column If Another String in Another Column

Option Explicit

Sub Additions()
    
    Dim ws As Worksheet: Set ws = ActiveSheet ' improve!
    
    Dim srg As Range
    Set srg = ws.Range("V2", ws.Cells(ws.Rows.Count, "V").End(xlUp))
    
    Dim drg As Range: Set drg = srg.EntireRow.Columns("BI")
    ws.Range("BI1").Value = "Comments"
    
    Dim sCell As Range
    Dim r As Long
    
    For Each sCell In srg.Cells
        r = r + 1
        If CStr(sCell.Value) = "DM" Then ' is a match
            drg.Cells(r).Value = "Developed Markets"
        'Else ' is not a match; do nothing
        End If
    Next sCell
 
    MsgBox "Additions finished.", vbInformation
    
End Sub
Related