Solved

Insert a blank row based on the value in a certain column

Posted on 2012-03-16
2
270 Views
Last Modified: 2012-06-21
I am trying to find a macro or add-in that will insert a new row when it finds a change in value in a particular column.  In example below, I want to be able to select column A (Team) and have Excel insert a new row when it finds a new value. In this case I'd get a new row under Team and then under 0123.


TEAM      SCHOOL      STYLE    EMBELLISH       GARMENT COLOR      
0123      PURDUE      BAC           WDMK         BLKOGD                     
0123      PURDUE      BAC      WDMK              BLKOGD                     
0143      BAYLOR      BAC      WDMK        HNTGLD                     
0150      GEORGIA      BAC           WDMK          BLKRED
0
Comment
Question by:Jeremyw
2 Comments
 
LVL 6

Accepted Solution

by:
wshark83 earned 250 total points
Comment Utility
try this:

Sub InsertLine()
    Dim i As Long
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If Cells(i - 1, 1) <> Cells(i, 1) Then
            Rows(i).Insert
        End If
    Next
End Sub
0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 250 total points
Comment Utility
You can also try a non looping macro

Sub insertbwteams()
    Dim LR As Long
    LR = Range("A2").End(xlDown).Row
    Range("A1:A" & LR).AdvancedFilter Action:=xlFilterCopy, criteriarange:="", CopyToRange:=Range("A" & LR + 1), Unique:=True
    Rows(LR + 1 & ":" & LR + 1).Delete Shift:=xlUp
    Range("A2:E8").Select
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("A2"), SortOn:=xlSortOnValues
    ActiveSheet.Sort.SetRange Range("A2:E" & Range("A2").End(xlDown).Row)
    ActiveSheet.Sort.Apply
End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now