Solved

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

Posted on 2012-03-16
2
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
wshark83 earned 250 total points
ID: 37729991
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
ID: 37730143
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

733 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