none
put data in first empty row in specific column RRS feed

  • Question

  • I am using VBA commands in excel 2007.

    I know how to put data into the first empty row in columns A & B.

    What I want to know is how to put data into the first empty row in columns C & D if there is already data in that row in columns A & B.

    Thanks for any help

    Thursday, June 9, 2016 1:23 PM

All replies

  • The best approach depends on the structure of your sheet, but something like

    Sub TestMacro()
        Dim r As Range
        
        Set r = Range("C1").End(xlDown)(2)
        
        If Cells(r.Row, "A").Value <> "" And Cells(r.Row, "B").Value <> "" Then
            r.Value = "What you want in Column C"
            r(1, 2).Value = "...and in Column D"
        Else
            MsgBox "Either A or B of row " & r.Row & " is empty."
        End If
    End Sub


    Thursday, June 9, 2016 7:39 PM