Untitled

 avatar
unknown
plain_text
2 years ago
887 B
6
Indexable
Sub SummarizeColumns()
    Dim lastRow As Long
    lastRow = ActiveSheet.Cells(Rows.Count, "Q").End(xlUp).Row
    Dim col As Long
    Dim startingCol As Long
    startingCol = 17 'Q column
    For i = 4 To lastRow
        Cells(i, "G").Value = "" 'clear existing data in G column
        Cells(i, "H").Value = "" 'clear existing data in H column
        For col = startingCol To ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
            If Cells(1, col).Value = "VO" Then
                Cells(i, "G").Value = Cells(i, "G").Value + Cells(i, col).Value
            End If
            If Cells(1, "Q").Value = "VO" Then
                If col Mod 2 = 0 then ' check if the column is even number
                    Cells(i, "H").Value = Cells(i, "H").Value + Cells(i, col).Value
                End If
            End If
        Next col
    Next i
End Sub
Editor is loading...