Solved

Insert blank row between different numbers.

Posted on 2014-04-08
8
517 Views
Last Modified: 2014-04-13
Good Day Experts,

I have a rather large excel spreadsheet in which column A has sorted numbers in with a single number 4, 10, 20 or more numbers that may be the same.  I would like if possible to have a macro that I would run that would insert one or two rows in the entire row to separate the different number or groups of like numbers throughout the column.

Thanks for your assistance.

I have attached a spreadsheet for your review.
0
Comment
Question by:Beeyen
  • 4
  • 4
8 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 39987513
Can't find the attachment
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 39987538
For now, my code looks like this:

Sub test()

'get row count
RowCount = ActiveSheet.UsedRange.Rows.Count

i = 1
Do While i < RowCount
    'get row and next row
    If Cells(i, 1).Value <> Cells(i + 1, 1).Value Then
		'insert row
        Cells(i + 1, 1).Select
        ActiveCell.EntireRow.Select
        Selection.Insert Shift:=xlDown
        'adjust i because of added row
		i = i + 1
    End If
    
    i = i + 1

Loop



End Sub

Open in new window

0
 

Author Comment

by:Beeyen
ID: 39988946
I have attached the spreadsheet.
Expert-workbook.xlsx
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 39988960
Because the third column is Yellow, I assume I have to check that. Therefore the code is only slightly different:

Sub test()

'get row count
RowCount = ActiveSheet.UsedRange.Rows.Count

i = 1
Do While i < RowCount
    'get row and next row
    If Cells(i, 3).Value <> Cells(i + 1, 3).Value Then
        'insert row
        Cells(i + 1, 3).Select
        ActiveCell.EntireRow.Select
        Selection.Insert Shift:=xlDown
        'adjust i because of added row
        i = i + 1
    End If
    
    i = i + 1

Loop



End Sub

Open in new window

0
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.

 

Author Comment

by:Beeyen
ID: 39988981
I tryed the coding you provided. It works but it inserts a row everyother number as oppose to grouping the like numbers then adding a row. I have attached the workbook for your use.  let me know
thanks
0
 

Author Comment

by:Beeyen
ID: 39989556
Okay! The coding worked down to a certain number of cells then stopped. I attached the worksheet and highlighted at the gray where the macro stopped.  Let me know

Thanks
Expert-workbook.xlsm
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 39989736
bug in code:

Sub test()

'get row count
RowCount = ActiveSheet.UsedRange.Rows.Count

i = 1
Do While i < RowCount
    'get row and next row
    If Cells(i, 3).Value <> Cells(i + 1, 3).Value Then
        'insert row
        Cells(i + 1, 3).Select
        ActiveCell.EntireRow.Select
        Selection.Insert Shift:=xlDown
        'adjust i because of added row
        i = i + 1
RowCount = RowCount + 1

    End If
    
    i = i + 1

Loop



End Sub

Open in new window

0
 

Author Closing Comment

by:Beeyen
ID: 39997732
Thanks
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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

23 Experts available now in Live!

Get 1:1 Help Now