+ Reply to Thread
Results 1 to 8 of 8

Create multiple blank rows and adding a formula in the first newly created blank row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    100

    Create multiple blank rows and adding a formula in the first newly created blank row

    Hi,

    This maybe really simple but it is driving me potty as I can't seem to find the solution.

    I have a spreadsheet that has numerous duplicated lines.

    Current Spreadsheet
    A B C
    1 A Dave £5.00
    2 A Dave £3.00
    3 B Steve £2.00
    4 B Steve £5.00
    5 B Steve £8.00
    6 C Sharon £2.00
    7 C Sharon £1.00
    8 C Sharon £10.00

    What I would like to do is to group the duplicated lines together that has a specific code , split the different duplicated codes by inserting three blank rows between them on the same worksheet and then adding a subtotal in a selected column within the first newly created blank row.


    What I hope to achieve
    A B C
    1 A Dave £5.00
    2 A Dave £3.00
    3 Total £8.00
    4
    5
    6 B Steve £2.00
    7 B Steve £5.00
    8 B Steve £8.00
    9 Total £13.00
    10
    11
    12 C Sharon £2.00
    13 C Sharon £1.00
    14 C Sharon £10.00
    15 Total £13.00


    I am able to group and add the blankrows with

    Sub InsertBlankRows()
    
    'Insert Blank Rows Between Duplicates
    
    Dim Duplicate As Worksheet
    Set Duplicate = ThisWorkbook.Worksheets("Duplicates")
    
    Duplicate.Activate
    
    Dim LastRow As Long, i As Long
    
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For i = LastRow To 3 Step -1
        If Cells(i, "S") <> Cells(i - 1, "S") Then
            Rows(i & ":" & i + 2).Insert
        End If
    Next i
    
    End Sub
    But for the life of me I can't add the sum totals in the newly acquire blank line and it is driving me insane. I've got this far with selecting the blank lines in column N


    Sub test()
    Dim r As Long
        On Error Resume Next
        r = Cells(Rows.Count, "m").End(xlUp).Row
        Range("n2:n" & r).SpecialCells(xlCellTypeBlanks).Select
        
    End Sub
    But I have no idea how to sum the values above the selected cell although it selecting the 3 blank lines instead of the 1

    Any help will be greatly appreciated as normal

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

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    Try this:
    Sub test()
    
    Dim B As Long
    Dim MyRNG As Range
    
    Set MyRNG = Range("N:N").SpecialCells(xlConstants, 1)
                
    For B = 1 To MyRNG.Areas.Count
        With MyRNG.Areas(B).Cells(MyRNG.Areas(B).Cells.Count).Offset(1)
            .Formula = "=SUM(" & MyRNG.Areas(B).Address(False, False) & ")"
        End With
        With MyRNG.Areas(B).Cells(MyRNG.Areas(B).Cells.Count).Offset(1)
            .Font.Bold = True
        End With
        With MyRNG.Areas(B).Cells(MyRNG.Areas(B).Cells.Count).Offset(1)
            .NumberFormat = "£#,##0.00"
        End With
    Next B
       
    End Sub

  3. #3
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    100

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    Kosherboy,

    You absolute genius!

    I have no idea how this works but it does

    Thank you

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

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    You're very welcome

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

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    Sorry, forgot to add "Total" and the previous was a bit redundant:

    Sub test()
    
    Dim B As Long
    Dim MyRNG As Range
    
    Set MyRNG = Range("N:N").SpecialCells(xlConstants, 1)
                
    For B = 1 To MyRNG.Areas.Count
        With MyRNG.Areas(B).Cells(MyRNG.Areas(B).Cells.Count).Offset(1)
            .Formula = "=SUM(" & MyRNG.Areas(B).Address(False, False) & ")"
            .Offset(, -1).Value = "Total"
            .Font.Bold = True
            .Offset(, -1).Font.Bold = True
            .NumberFormat = "£#,##0.00"
        End With
    Next B
       
    End Sub
    Last edited by kosherboy; 02-20-2018 at 10:50 AM.

  6. #6
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    100

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    Sorry Kosherboy, how do I add the 'total' in the column next to the formula?

  7. #7
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    100

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    Sorry, should learn to read from the top down.

    Thanks again

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

    Re: Create multiple blank rows and adding a formula in the first newly created blank row

    if i helped resolve your question please click the "*" button to the left of my post for reputation.

    Thanks!

+ 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. [SOLVED] Formula to Skip Blank Rows and Pull the Next Non-Blank
    By karimel_romeo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-19-2017, 01:04 PM
  2. [SOLVED] Copy rows to a newly created tab
    By alexduy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-09-2016, 10:30 AM
  3. [SOLVED] Update VBA code - remove blank rows in newly created sheets
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2016, 03:17 PM
  4. How to create a macro to insert blank rows and copy data into blank rows?
    By zodiack101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 01:18 PM
  5. Replies: 0
    Last Post: 07-16-2013, 01:20 PM
  6. Mac Excel: Hiding rows if cell blank, when being blank depends on a conditional formula
    By lee_5_5 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-06-2013, 11:25 PM
  7. Copying colums of formula and adding blank rows
    By tallgingerbloke in forum Excel General
    Replies: 8
    Last Post: 07-02-2011, 01:59 PM

Tags for this Thread

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