Results 1 to 6 of 6

Copy formula and paste same row to last column used

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Copy formula and paste same row to last column used

    Hello,

    I have been struggling with finding the last used column and pasting a formula in the same row to the last column. Here is what I have used and it isn't working.:

    Sub Subtotal()
    
        Dim LastRow As Long
        Dim LastCol As Long
        Dim lastcell As String
    
       'Define Variables
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        ActiveSheet.UsedRange.Select
        LastCol = Range("A" & Columns.Count).End(xlToLeft).Column
        lastcell = ActiveCell.SpecialCells(xlLastCell).Address
        iLastColumn = Range("A7").End(xlToRight).Row
        a = Cells(7, Columns.Count).End(xlToLeft).Column
    
        Range("R1").Select
        Selection.NumberFormat = "#,##0"
        ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[" & LastRow & "]C)"
        Range("R1").Select
        Selection.Copy
    'it errors out at next line, I just want to take the ActiveCell.Formula above and copy it all the way to the last column used.
        Range("R1:" & iLastColumn).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
    Any thoughts?

    Many thanks!
    Matt
    Last edited by matt4003; 05-11-2009 at 06:19 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1