ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to move row to last row (https://www.excelbanter.com/excel-programming/396917-macro-move-row-last-row.html)

Jennifer

Macro to move row to last row
 
I have a handful of montly invoices, where the line items increase / decrease
the amount of rows I may have from month to month. The client wants us to
have Invoice Number and the Date at the bottom of the page.

I have it setup that G48 has Invoice Number and H48 has a date formula,
justified so it shows "Invoice # - Date" We want our logo image below that,
so I have that setup as a footer. Excel is finicky with image footers, so
having the Invoice # & Date in the footer does not play nice with the logo.
I'm just trying to think of a macro that I could run either manually or on
save / exit that would move those 2 cells to the last row of the worksheet.
We use A4 paper. I hope this enough information & thanks for the assistance.

SixSigmaGuy[_2_]

Macro to move row to last row
 
This might help. It will tell you what the last row is, then you can simply
copy the data from the current place to the new place:

Function iLastRowFilledInColumn(ws As Excel.Worksheet, iColumn As Long) As
Long
Dim iLastRow As Long

iLastRow = ws.Cells(ws.Rows.Count, iColumn).End(xlUp).Row
'
' If the entire column is empty, Excel still returns 1 even though
' there is no data in row 1. Therefore, check to see if the
' cell is empty; if it is, return 0 instead of 1.
'
If iLastRow = 1& Then
If Trim(ws.Cells(iLastRow, iColumn)) = "" Then
iLastRow = 0&
End If
End If

iLastRowFilledInColumn = iLastRow
End Function

"Jennifer" wrote:

I have a handful of montly invoices, where the line items increase / decrease
the amount of rows I may have from month to month. The client wants us to
have Invoice Number and the Date at the bottom of the page.

I have it setup that G48 has Invoice Number and H48 has a date formula,
justified so it shows "Invoice # - Date" We want our logo image below that,
so I have that setup as a footer. Excel is finicky with image footers, so
having the Invoice # & Date in the footer does not play nice with the logo.
I'm just trying to think of a macro that I could run either manually or on
save / exit that would move those 2 cells to the last row of the worksheet.
We use A4 paper. I hope this enough information & thanks for the assistance.


Jennifer

Macro to move row to last row
 
SixSigmaGuy,

Thank you for the response. That is a good solution to a more complex
problem, but doesn't really save anymore time (maybe a little) than just
using the Page Break Preview and inserting or deleting the amount of rows
that places it at the end of the end of the worksheet. I was just hoping to
take it one step further, if possible. Mostly because I forget to go back to
look at it before print, then have to reprint (the little tree-hugger inside
hates that).

Jennifer

"SixSigmaGuy" wrote:

This might help. It will tell you what the last row is, then you can simply
copy the data from the current place to the new place:

Function iLastRowFilledInColumn(ws As Excel.Worksheet, iColumn As Long) As
Long
Dim iLastRow As Long

iLastRow = ws.Cells(ws.Rows.Count, iColumn).End(xlUp).Row
'
' If the entire column is empty, Excel still returns 1 even though
' there is no data in row 1. Therefore, check to see if the
' cell is empty; if it is, return 0 instead of 1.
'
If iLastRow = 1& Then
If Trim(ws.Cells(iLastRow, iColumn)) = "" Then
iLastRow = 0&
End If
End If

iLastRowFilledInColumn = iLastRow
End Function

"Jennifer" wrote:

I have a handful of montly invoices, where the line items increase / decrease
the amount of rows I may have from month to month. The client wants us to
have Invoice Number and the Date at the bottom of the page.

I have it setup that G48 has Invoice Number and H48 has a date formula,
justified so it shows "Invoice # - Date" We want our logo image below that,
so I have that setup as a footer. Excel is finicky with image footers, so
having the Invoice # & Date in the footer does not play nice with the logo.
I'm just trying to think of a macro that I could run either manually or on
save / exit that would move those 2 cells to the last row of the worksheet.
We use A4 paper. I hope this enough information & thanks for the assistance.



All times are GMT +1. The time now is 07:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com