Need macro to start at a new line

G

Guest

I am creating a macro that will add additional lines before my "Total" line
at the bottom of my worksheet. Sometimes I have to add additional items to
my order form and I need them included in the total.

I created the macro, but each time I run it, the macro inputs the new rows
at the cell where I originally set the macro to input rows. For example,
when I recorded the macro my total line was line 25. So, I went to line 24,
copied it and inserted the copied row. I set the macro to add 5 rows. When
I reach row 30 and I try to add 5 more rows using the macro, it runs by
starting back at row 24, instead of row 29.

Any suggestions...Thanks
 
G

Guest

lastRow = Sheets("sheetname").Cells(Rows.Count, "A").End(xlUp).Row
This will get you the last used row in column A, change as necessarry.
 
G

Guest

This should give you what you want:
Sub TestForLastRow()
Cells(LastRow(), 1).Select
End Sub

Public Function LastRow(Optional wks As Worksheet) As Integer
If wks Is Nothing Then Set wks = ActiveSheet
LastRow = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
End Function

Hope it helps,
Ryan--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top