SolvedPrivate

Seperate Data with VBA

Posted on 2015-02-10
4
25 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 50

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input box prompt with only 5 possible entries 5 38
Excel IF statement 4 20
add a column label to a list object using VBA 2 17
Pull Phone Number out of Cell 3 10
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
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.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

679 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