+ Reply to Thread
Results 1 to 8 of 8

VBA to add a blank row between entries

  1. #1
    Registered User
    Join Date
    06-14-2011
    Location
    Princeton, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA to add a blank row between entries

    First off: Windows 7 and Excel 2010

    I have a massive spreadsheet and need to put a blank row after entries when the information in column T changes. Let's say the following is column T.

    Blue
    Blue
    Blue
    Red
    Red
    Red
    Yellow

    I want to insert a blank row after the 3rd Blue and 3rd Red and so on........ Below is the VBA someone gave me to try in Excel 07 and it worked perfectly. Perhaps it will help with your answer. It does not work in Excel 2010. Thank you in advance.

    Please Login or Register  to view this content.
    Last edited by Cutter; 07-31-2012 at 10:11 AM. Reason: Added code tags

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: VBA to add a blank row between entries

    Hi Mangus,

    Try below quick code:-

    Please Login or Register  to view this content.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    06-14-2011
    Location
    Princeton, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA to add a blank row between entries

    Ok, very good but not EXACTLY what I'm looking for. That puts a blank row after every entry. I only want a blank row after an entry if the following entry is different in column T. See Below.

    Start with this:

    Red
    Red
    Red
    Red
    Blue
    Blue
    Green
    Green
    Black
    Yellow

    I want to end up with this:

    Red
    Red
    Red
    Red

    Blue
    Blue

    Green
    Green

    Black

    Yellow

  4. #4
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: VBA to add a blank row between entries

    Hi MangusColo,

    I am getting correct results when tried that macro.. do you have two columns of data ?
    Please upload a sample workbook. thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  5. #5
    Registered User
    Join Date
    06-14-2011
    Location
    Princeton, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA to add a blank row between entries

    Here is a sample workbook. Column T is the column in question that I want it sorted on. Not sure I attached it correctly. Let me know.SampleMangus.xlsx

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA to add a blank row between entries

    Hi guys,

    I think dilipandey has his active cell in T1 and MangusColo has his active cell in A1.

    @ dili - do a Cells(1,"T").Select after you select the current region and see if that corrects his problem.

    hope that helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: VBA to add a blank row between entries

    Hi Mangus,

    Okay.. I got it, you have the data column as column T. Try using below code:-

    Please Login or Register  to view this content.
    Thanks MarvinP for the heads-up

    Cheers

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  8. #8
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: VBA to add a blank row between entries (1000 rows data in column("B:B"))

    Time: 0.047/2.515

    PHP Code: 
    Option Explicit
    Dim Timer_ 
    As Double
    Sub InsertBlankRowsForArr
    ()
     
    Dim Rws As LongwW As LongZz As LongFf As Long
     
     Timer_ 
    Timer
     Rws 
    Cells(Cells.Rows.Count"B").End(xlUp).Row
     ReDim Arr
    (1 To 2 Rws)
     
     
    ReDim ArrT(1 To Rws 1)
     
    ArrT() = Range("B1:B" Rws 1)
     
     
    Zz Rws 1:                          Arr(Zz) = "A0"
     
    For wW 1 To Rws
        Arr
    (wW) = "A" Ff
    '    If Cells(wW + 1, "B").Value <> Cells(wW, "B").Value Then
        If ArrT(wW + 1, 1) <> ArrT(wW, 1) Then
        
            Zz = Zz + 1:                    Ff = Ff + 1
            Arr(Zz) = "A" & Ff & Zz
        End If
     Next wW
     Range("A1:A" & 2 * Rws).Value = WorksheetFunction.Transpose(Arr)
     
     Columns("A:B").Select
     Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False
     Columns("A:A").Select
     Selection.ClearContents
     [HH65500].End(xlUp).Offset(1).Value = Timer - Timer_
    End Sub 

+ Reply to Thread

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