+ Reply to Thread
Results 1 to 3 of 3

Insert rows when column A data changes then shade and autosum blanks in columns E to I

  1. #1
    Registered User
    Join Date
    08-24-2017
    Location
    South Africa
    MS-Off Ver
    2010
    Posts
    2

    Insert rows when column A data changes then shade and autosum blanks in columns E to I

    I currently have a macro which inserts a row whenever the data in column A changes. What I want to add is that it also shades and autosums columns E throught to I as well.

    Could somebody please help me with this?

    Here is the code that I am using to insert a row when the data in column A changes

    Sub InsRowsWhenCellDataChangesColA()
    Dim r As Long, mcol As String, i As Long

    ' find last used cell in Column A
    r = Cells(Rows.Count, "A").End(xlUp).Row

    ' get value of last used cell in column A
    mcol = Cells(r, 1).Value

    ' insert rows by looping from bottom
    For i = r To 2 Step -1
    If Cells(i, 1).Value <> mcol Then
    mcol = Cells(i, 1).Value
    Rows(i + 1).Insert
    End If
    Next i

    End Sub


    I have attached the sample data before any changes and the preferred output that I would like to achieve.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Insert rows when column A data changes then shade and autosum blanks in columns E to I

    Consider using the Subtotals feature.

    Excel Subtotals
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-24-2017
    Location
    South Africa
    MS-Off Ver
    2010
    Posts
    2

    Re: Insert rows when column A data changes then shade and autosum blanks in columns E to I

    I tried to use the Macro Recorder and the result was

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
    Application.Run "PERSONAL.XLSB!InsRowsWhenCellDataChangesColA"
    Columns("E:I").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -0.149998474074526
    .PatternTintAndShade = 0
    End With
    Range("E4:I4").Select
    Selection.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
    Range("E25:I25").Select
    Selection.FormulaR1C1 = "=SUM(R[-20]C:R[-1]C)"
    Range("E32:I32").Select
    Selection.FormulaR1C1 = "=SUM(R[-6]C:R[-1]C)"
    Range("E39:I39").Select
    Selection.FormulaR1C1 = "=SUM(R[-6]C:R[-1]C)"
    Range("E50:I50").Select
    Selection.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
    Range("E52:I52").Select
    Selection.FormulaR1C1 = "=SUM(R[-1]C)"
    Range("E54:I54").Select
    Selection.FormulaR1C1 = "=SUM(R[-1]C)"
    Range("E64:I65").Select
    Selection.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
    ActiveWindow.SmallScroll Down:=12
    Rows("65:65").Select
    Selection.Delete Shift:=xlUp
    Range("L51").Select
    ActiveWindow.SmallScroll Down:=-57
    Columns("G:G").Select
    Selection.Cut
    Columns("I:I").Select
    Selection.Insert Shift:=xlToRight
    With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
    End With
    ActiveWindow.FreezePanes = True
    Range("J6").Select
    ActiveWindow.SmallScroll Down:=-9
    End Sub



    Problem is that the data on my sheets are of varying lengths, so this does not work on one of the other sheets.

    I would really appreciate it if someone could help as I have many spreadsheets where this would save me a lot of time on a daily basis.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 12
    Last Post: 05-26-2014, 09:04 PM
  2. [SOLVED] Insert and Delete blanks rows so that there are 2 blanks rows between text rows
    By erniedawg in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-29-2013, 02:27 AM
  3. Replies: 3
    Last Post: 04-12-2013, 04:36 PM
  4. [SOLVED] VBA Macro - Insert Rows based on different Column Value but Ignoring Blanks Cells
    By WITJ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2013, 03:11 PM
  5. Macros to insert 2 blank row and autosum a column after every 200 rows in data range.
    By sachinsingh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2013, 09:55 AM
  6. [SOLVED] Macro To AutoSum Columns With Rows That Will Vary When The Report Is Run
    By Macro Fool in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2012, 10:54 AM
  7. Replies: 3
    Last Post: 11-15-2010, 08:26 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