VBA To Add New Row Last Row Has Data

AcornNut

Board Regular
Joined
Aug 19, 2014
Messages
51
I am trying to create a a vba code to a supply order form that adds a new row only if the last row has data.

I have a separate inventory sheet and vba that searches that inventory sheet for shortages and expired items, then automatically fills in the supply order form with those items and quantities. However, the form only goes from row 24 to row 53 (one page). If I have a lot of items to order, I don't have enough room on the form. I'm trying to see if I can have the code add an additional row to the end of the list (there is some data below the table that needs to stay below - thus move down with each additional row) only when needed.

Right now the code begins at row 53, looks up until a row with data is found, then drops one row and adds the needed supply data. The problem begins when row 53 is used and more items are needed. I need to have the code add a "row 54" and add the additional data, and then "row 55", and so on, until all the items needed are listed.

Any ideas or help would be greatly appreciated.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hopefully, this code snippet will get you started and you can modify it to do what you need.
If it doesn't, please provide more detail:
Code:
Sub MyInsertRow()

    Dim lastRow As Long
    
'   Find last row populated with data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   If row number is greater than or equal to 53, add a new row
    If lastRow >= 53 Then
        Rows(lastRow + 1).Insert
    End If
    
'   Select column A new row for adding data
    Cells(lastRow + 1, "A").Select
    
End Sub
 
Upvote 0
Thanks for the help! That did it! I've even added another line to copy the format of the "lastRow" to the new row. Now....to figure out how to get the data to copy correctly.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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