Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Excel macro total row (https://www.askmehelpdesk.com/showthread.php?t=105029)

  • Jun 28, 2007, 06:34 AM
    ssheldon
    Excel macro total row
    Hello,

    I currently have a small problem with a macro in Excel. I am pasting various amounts of rows of information into new workbooks all the time and have created a macro that will sort/tart-up the info. The problem I have is that I wish to attach a 'Total' row after the last line of information (Shown below). Now, the problem I have is that because the information I am pasting into the workbook is a different amount of lines each time, the total line is fixed on the row that the macro was created with, (this is all shown below). I want the macro to be able to distinguish the last row of the information in the workbook and then insert a 'Total' row on the next line down. This is shown below as the total line being stuck on H49:I49 (e.g. the information I pasted in was 48 lines long), so if I was to paste in information that was 100 lines long and played the macro, the total column will still be inserted into the 49th row which is in the centre of the info.


    Selection.Borders(xlEdgeRight).Line
    Selection.Borders(xlInsideVertical).Line
    Range("A49").Select
    ActiveWindow.SmallScroll Down:=6
    ActiveCell.FormulaR1C1 = "Total"
    Range("H49").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-43]C:R[-1]C)"
    Range("I49").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-43]C:R[-1]C)"
    Range("A49:I49").Select
    Selection.Font.Bold = True


    Please can you help me out with this. Hopefully I only need to replace the H49 and I49 with a final column command, but as you can see I'm not an expert at macros.

  • All times are GMT -7. The time now is 08:01 AM.