EXCEL VBA - Loop through cells in a column, if not empty, print cell value into another column

前端 未结 2 1256
失恋的感觉
失恋的感觉 2020-12-20 07:18

I\'m very new to Excel VBA and haven\'t quite familiarized myself with all the different functions and such, and I\'m quite sure I understand how to use IF statements within

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 07:45

    Give this a try:

    Sub FoodPicker()
        Dim N As Long, i As Long, j As Long
        N = Cells(Rows.Count, "A").End(xlUp).Row
        j = 2
        For i = 2 To N
            If Cells(i, "B").Value = "Yes" Then
                Cells(j, "C").Value = Cells(i, "A").Value
                j = j + 1
            End If
        Next i
    End Sub
    

    and if you are willing to use 1,2,3 instead of yes,yes,yes you can avoid the macro.

提交回复
热议问题