VBA - Inserting Rows Based on count of adjacent cells with data

982 Views Asked by At

Here is my scenario: 10 Columns from A to J, 100 rows. Each row can have any where from 1 to 10 entries.

I need to count the number of cells with data in each row, and insert that same amount of rows beneath the row that was just counted.

EX: Row 1 has entries in Columns A-D, then I'd need 4 rows inserted below row 1. EX2: Row 20 has entries in columns A-G, then i'd need 7 rows inserted below row 20

Any help is greatly apprecaited

1

There are 1 best solutions below

0
On

This isn't a complete answer, but hopefully it'll push you in the right direction (I'm pretty new to programming myself).

Dim RowNum as integer
Dim ColNum as integer
Dim NumRowsToInsert as integer


For RowNum=100 to 1
    NumRowsToInsert=0
    For ColNum=1 to 10
        If cell  has value, then
        NumRowsToInsert=NumRowsToInsert+1
        End if
    Next ColNum    
    insert coding to insert "NumRowsToInsert" rows below row "RowNum" here
Next RowNum

This logic should work for you. But you'll need to fix the coding.