Rob
Rob

Reputation: 428

How Do I Find the Next Empty Row

I'm writing a Macro that finds the next empty row and then appends a set of data into it, Row 1 should always be taken as that is my header Row but my code seems to just be overwriting the header in row 1. I've done some basic debugging and I've tried changing the code for what my variable row is but I've either gotten errors or nothing and this has been the first one to paste my date except that it is pasting my data into just row 1.

Sub MEData()
    ' Find Next Empty Row & Append ME Data
    Dim headers() As Variant
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim row As Integer
    row = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).row
    Application.ScreenUpdating = False
    Set wb = ActiveWorkbook
    Set ws = ThisWorkbook.Sheets("ME Data")
    If DesignChangeECN = "" Then
        DesignChangeECN = "Not Design Change"
    End If
    
    headers() = Array(VBA.Environ("UserName"), Now(), MPP_ECN, MPP_ECN_Description, _
    DesignChangeECN, Dept, ShortChangeDescription, ChangeType, "Additional Notes", _
    "Open", "Submitted")
    
    Rows(row).Insert shift:=xlShift ' Insert Into Next Empty Row
    With ws
    For i = LBound(headers()) To UBound(headers())
        .Cells(1, 1 + i).Value = headers(i)
        Next i
    End With
End Sub

enter image description here

So here the Macro above replaced the header with my data and if I run it again it would just replace the data with another copy...

I'm not quite sure how I can get this to ignore Row 1 and just continually append data to the next row.

Upvotes: 0

Views: 5881

Answers (1)

Immobilizer
Immobilizer

Reputation: 46

Use this

LastRow=Cells(Rows.Count, 1).End(xlup).Row + 1

Upvotes: 2

Related Questions