Find the first blank row

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
54
Office Version
  1. 365
Platform
  1. Windows
Hello Everybody,

I'd like to paste information into a table, but unfortunately either the lines are written on top of each other
VBA Code:
DerniereLigne = Range("A" & Rows.Count).End(xlUp).Row

or there is always a blank row at the top of the table (Row 2).
VBA Code:
DerniereLigne = Range("A" & Rows.Count).End(xlUp).Row + 1

Do you know how to write from the row 2, please?

VBA Code:
Sub essai2()

    
    ThisWorkbook.Worksheets("Feuil2").Activate
    
'   Find the last row
    DerniereLigne = Range("A" & Rows.Count).End(xlUp).Row
    
'   Display the number of the last row
    MsgBox "The last blank row is : " & " " & DerniereLigne


End Sub

Thanx a lot for your help
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Something like this might work for you:

VBA Code:
Sub essai2()

    Dim ws As Worksheet
    Dim DerniereLigne As Long
    
    Set ws = ThisWorkbook.Worksheets("Feuil2")
    
'   Find the last row
    DerniereLigne = ws.Range("A" & Rows.Count).End(xlUp).Row
    ' The cell should only be empty if there is nothing in the column
    If ws.Cells(DerniereLigne, "A").Value <> "" Then DerniereLigne = DerniereLigne + 1
    
        
'   Display the number of the last row
    MsgBox "The last blank row is : " & " " & DerniereLigne

End Sub
 
Upvote 0
Or maybe this seeing you have a table and the headers must be in row 1
VBA Code:
Sub essai2()

    Dim ws As Worksheet
    Dim firstblankrow As Long
    
    Set ws = ThisWorkbook.Worksheets("Feuil2")
    
'   Find first blank row in column A
    firstblankrow = ws.Columns(1).Find(What:="", SearchDirection:=xlNext, SearchOrder:=xlByRows).Row
    
    MsgBox "The first blank row is :   " & firstblankrow
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top