Solved

Insert blank row between different numbers.

Posted on 2014-04-08
8
514 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

746 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

9 Experts available now in Live!

Get 1:1 Help Now