Untitled

 avatar
unknown
plain_text
22 days ago
999 B
2
Indexable
Private Sub RemoveBlankCountryRows(wsReport As Worksheet, startCol As Long, endCol As Long)
    Dim lastRow As Long, i As Long, j As Long
    lastRow = wsReport.Cells(wsReport.Rows.Count, 1).End(xlUp).Row
    
    ' Loop from the bottom to the top to avoid shifting rows during deletion
    For i = lastRow To 4 Step -1
        Dim isRowEmpty As Boolean
        isRowEmpty = True  ' Assume the row is empty initially
        
        ' Check all cells in the country-specific range (from startCol to endCol)
        For j = startCol To endCol
            If wsReport.Cells(i, j).Value <> "" Then
                isRowEmpty = False  ' If any cell in the range is non-empty, set to False
                Exit For  ' Exit the loop as we only need to find one non-empty cell
            End If
        Next j
        
        ' If the row is empty (both country-specific columns are blank), delete the row
        If isRowEmpty Then
            wsReport.Rows(i).Delete
        End If
    Next i
End Sub
Leave a Comment