I'm new to VBA.
2 worksheets in the same workbook. I want to get the last empty row number from worksheet 2 and past that number into a cell on worksheet 1.
Anyone, please help. Thanks!
I'm new to VBA.
2 worksheets in the same workbook. I want to get the last empty row number from worksheet 2 and past that number into a cell on worksheet 1.
Anyone, please help. Thanks!
 
    
    enter code hereThe last empty row in a worksheet is usually at or near the bottom the the worksheet.  So we start at the end and work our way up:
Sub qwerty()
    Dim N As Long, wf As WorksheetFunction
    Dim s1 As Worksheet, s2 As Worksheet
    Set wf = Application.WorksheetFunction
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    For N = Rows.Count To 1 Step -1
    If wf.CountA(s2.Cells(N, 1).EntireRow) = 0 Then
        s1.Range("B9").Value = N
        Exit Sub
    End If
    Next N
End Sub
EDIT#1:
To get the first empty row rather than the last empty row, use:
Sub qwerty()
        Dim N As Long, wf As WorksheetFunction
        Dim s1 As Worksheet, s2 As Worksheet
        Set wf = Application.WorksheetFunction
        Set s1 = Sheets("Sheet1")
        Set s2 = Sheets("Sheet2")
        For N = 1 to Rows.Count
        If wf.CountA(s2.Cells(N, 1).EntireRow) = 0 Then
            s1.Range("B9").Value = N
            Exit Sub
        End If
        Next N
    End Sub
