Results 1 to 11 of 11

Macro to to enter value underneath last row in the last column

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Macro to to enter value underneath last row in the last column

    Hi.
    Can anybody modify for me the code below so that the code will add the total sum of the last column underneath the last row? The code below works only for the last row in column "E", but I want the code to be flexible and detect the last column as well. Please note that my code also has an "auto fill down" which I would like to put in the last column as well.
    Thanks in advance.


    Sub Last_row_last_column()
    
    Dim ws As Worksheet:    Set ws = Sheets("Sheet1")
    Dim LR As Long, rCell As Long
        
    'misc
    LR = ws.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    'Part A
    If IsEmpty(ws.Range("D18")) Then
        ws.Range("D18").Formula = ""
        ws.Range("E18").Formula = ""
    End If
    
    ws.Range("D18:E18").Resize(LR - 18 + 1, 2).FillDown
    
    'Part B
    For rCell = LR To 18 Step -1
        If ws.Range("C" & rCell).Value = 0 Then
            ws.Range("C" & rCell).EntireRow.Delete Shift:=xlUp
        ElseIf ws.Range("C" & rCell).Value = "" Then
            ws.Range("C" & rCell).EntireRow.Delete Shift:=xlUp
        End If
    Next rCell
    
    With ws.Range("E" & LR + 1)
        .Formula = "=SUM(E18:E" & LR & ")"
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Font.Bold = True
        .Font.Name = "Cambria"
        .Font.Size = 8
    End With
    
    'Clean Up
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by kosherboy; 02-03-2014 at 11:04 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  2. VBA Halp! Sort Columns by date; Insert/add Data Underneath the Cell in Column B
    By goradiar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-06-2012, 09:10 AM
  3. Replies: 0
    Last Post: 05-17-2012, 12:59 PM
  4. Vertical to horizontal one column and underneath
    By vinaynaran in forum Excel General
    Replies: 2
    Last Post: 10-14-2009, 01:02 PM
  5. macro to copy a column and put it underneath another
    By cadalist in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2007, 06:59 PM

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