SolvedPrivate

Seperate Data with VBA

Posted on 2015-02-10
4
23 Views
Last Modified: 2016-02-10
I have an Excel 2010 file.  I want to be able to insert a blank row each time I see a value change.

Example:
DATE     VALUE
9/1/14      AB
9/2/14      AB
9/1/14      AC
9/8/14      AC

What I am wanting to do is separate the AB and AC data with a blank row with VBA.

So I would like to make my sheet look like this:

Example:
DATE     VALUE
9/1/14      AB
9/2/14      AB

9/1/14      AC
9/8/14      AC

Can you point me in the right direction to accomplish this?
Thanks.
0
Comment
Question by:gwlanks
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:James Elliott
James Elliott earned 250 total points
ID: 40600827
Something like this should work.

Sub EE()

Dim i As Long

For i = Range("B" & Application.Rows.Count).End(xlUp).Row To 2 Step -1

    If Not Range("B" & i - 1).Value = Range("B" & i).Value Then Range("B" & i).Rows.Insert xlShiftDown
    
Next i

End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:James Elliott
ID: 40600834
To implement:

(1) Hit Alt+F11 to open the VB Editor
(2) Double click the sheet on the left that contains your data
(3) Paste the code above on the right hand side
(4) Close the VB Editor
(5) Run the Macro
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 40600862
Hi,

EDITED Code ' No blank row after first line and entirerow inserted
Sub EE()

Dim i As Long

For i = Range("B" & Application.Rows.Count).End(xlUp).Row To 3 Step -1

    If Not Range("B" & i - 1).Value = Range("B" & i).Value Then Range("B" & i).EntireRow.Insert xlShiftDown
    
Next i

End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:gwlanks
ID: 40600894
After some tweaking on my side for the column it worked great.  Thank you very much for the fast response and your help is much appreciated.

Thanks,
Greg
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

914 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