lundi 19 juin 2017

VBA - multiple conditions for each cell

I'm trying to solve this code's issue, which I can't run:

'========================================================================
' CHECKS IF MARKET SECTOR IS EMPTY (FOR LEDGER)
'========================================================================

Private Sub Fill_MarketSector()

Dim LastRow As Long
Dim rng As Range, C As Range

With Worksheets("Ready to upload") ' <-- here should be the Sheet's name
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row ' last row in column A
    Set rng = .Range("A2:A" & LastRow) ' set the dynamic range to be searched
    Set rng2 = .Range("F2:F" & LastRow)

    ' loop through all cells in column A and column F
    For Each C In rng and For Each C in rng2
        If rng.C.Value = "Ledger" and rng2.C.value IsEmpty Then
            C.Value = "599" ' use offset to put the formula on column "L"
        End If
    Next C
End With

End Sub

The code should check if the column A contains word "Ledger" and column F is empty, then it should put into column F "599". It should always check to the very last row. Could you help me, please?

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire