SolvedPrivate

Seperate Data with VBA

Posted on 2015-02-10
4
27 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
[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
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 51

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

Technology Partners: 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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

717 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