Solved

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

Posted on 2012-03-16
2
279 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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.

831 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