Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding 1st empty row

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
GB
This is probably really basic and/or really simple! But it's got me baffeled!

What I would like to do is to insert a new record on the 1st available row. I have previously tried setting the row number that it should start from and then incrementing the new row number but it just reset itself each time the button was clicked :-( The insert works it's just the finding the empty row that doesn't.

Can anybody help me with this PLEASE!!!!!

Thank you


[PC2]
 
Hi Jane,

Try the following:

Sub test()
For i = 1 To 65536
If IsEmpty(Cells(i, "A")) Then
Cells(i, "A").EntireRow.Insert
Exit Sub
End If
Next i
End Sub

Cheers

John
 
One way to return the next row that is available (if all of the cells in Column A in the table are filled) is:
Code:
Dim LastRow As Integer
LastRow = [A65536].End(xlUp).Row
Cells(LastRow + 1, 1).Select

If you want to enter the data into the first empty cell and all of the cells in Column A are not filled then use John's solution. ;-)

I hope this helps!


Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Or.....

Sub test()
Range("A1").End(xlDown).EntireRow.Insert
End Sub

 
Actually, if you have blanks in the table's A Column and you want to select the first empty cell, you could use a variation of my last post:

Code:
Dim LastRow As Integer
LastRow = [A1].End(xlDown).Row
Cells(LastRow - 1, 1).Select

Good Luck!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Hi,

I agree in principle but disagree on the specifics, Mike.
Code:
Dim LastRow As Long
LastRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
1. Row value variables should be Long and NOT Integer
2. You should avoid using the Activate an Select Methods for Excel objects whenever possible -- see my FAQ faq707-4105

:)

Skip,
Skip@TheOfficeExperts.com
 
Thank you all of you for your help.

I've now got the coding working, with a bit of tweeking :)

Thanks again

Jane :)

[PC2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top