Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Need macro to start at a new line
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 |
#2
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Need macro to start at a new line
lastRow = Sheets("sheetname").Cells(Rows.Count, "A").End(xlUp).Row
This will get you the last used row in column A, change as necessarry. -- -John Please rate when your question is answered to help us and others know what is helpful. "MHenderson" wrote: 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 |
#3
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Need macro to start at a new line
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-- -- RyGuy "John Bundy" wrote: lastRow = Sheets("sheetname").Cells(Rows.Count, "A").End(xlUp).Row This will get you the last used row in column A, change as necessarry. -- -John Please rate when your question is answered to help us and others know what is helpful. "MHenderson" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I start the line graph at 0 on the x axis instead of 1? | Charts and Charting in Excel | |||
How do you start a new line within a cell? | New Users to Excel | |||
make line in chart start at y axis | Charts and Charting in Excel | |||
how can I start a new line when entering data into a word wrapped. | Excel Discussion (Misc queries) | |||
when displaying formulas, how to start a new line in the same cel. | Excel Discussion (Misc queries) |