Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-16
2
Medium Priority
?
296 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 750 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 750 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

704 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