SolvedPrivate

Seperate Data with VBA

Posted on 2015-02-10
4
22 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
Comment Utility
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
Comment Utility
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 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

14 Experts available now in Live!

Get 1:1 Help Now