Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 772
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,836
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I start the line graph at 0 on the x axis instead of 1? Jo Charts and Charting in Excel 2 April 30th 23 12:25 PM
How do you start a new line within a cell? [email protected] New Users to Excel 4 August 12th 05 02:39 PM
make line in chart start at y axis Tone Charts and Charting in Excel 1 May 5th 05 09:23 AM
how can I start a new line when entering data into a word wrapped. spozzie Excel Discussion (Misc queries) 2 March 31st 05 05:51 AM
when displaying formulas, how to start a new line in the same cel. EL Excel Discussion (Misc queries) 1 December 7th 04 07:18 AM


All times are GMT +1. The time now is 01:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"