Simple macro help, pleeeeeaaase?! :)

fingerstyle

New Member
Joined
Aug 28, 2017
Messages
7
Hi,

I really hope someone here can help - I just signed up here to post an urgent question. I have been using Excel for decades but never went beyond recording macros so I don't know if there is a macro that you can write to allow me to do this - to insert the number of rows that I type at the leftmost column - see below. The idea is that these are newly added items with the same item ID, and therefore need the blank rows to inherit data in the existing table. (and preferably, those newly pasted data are coloured in, say, green so that I know those are the changes that I need to review and check.

As part of my day job, I'm having to to this for a few thousand lines so this macro would come in as a time saver.

THANK YOU!!!


Current state - but want data for existing ID copied down to newly added but same IDs:

Insert x rows
Data IDData 1Data 2Data 3Data 4Data 5

Data ID 01Data 01Data 02Data 03Data 04Data 05

Data ID 02Data 01Data 02Data 03Data 04Data 05

Data ID 03Data 01Data 02Data 03Data 04Data 05

Data ID 03Data 01Data 02Data 03Data 04Data 05
1
Data ID 03New Data 01



1
Data ID 03New Data 02



1
Data ID 03New Data 03



1
Data ID 03New Data 04




Data ID 04Data 01Data 02Data 03Data 04Data 05

Data ID 05Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06New Data 08



3
Data ID 06New Data 09



3
Data ID 06New Data 10



3
Data ID 06New Data 11



3
Data ID 06New Data 12




<tbody>
</tbody>



Desired end-state (green fonts are desired additions)
Insert x rows
Data IDData 1Data 2Data 3Data 4Data 5

Data ID 01Data 01Data 02Data 03Data 04Data 05

Data ID 02Data 01Data 02Data 03Data 04Data 05

Data ID 03Data 01Data 02Data 03Data 04Data 05

Data ID 03Data 01Data 02Data 03Data 04Data 05
1
Data ID 03New Data 01Data 02Data 03Data 04Data 05

Data ID 03New Data 01Data 02Data 03Data 04Data 05
1
Data ID 03New Data 02Data 02Data 03Data 04Data 05

Data ID 03New Data 02Data 02Data 03Data 04Data 05
1
Data ID 03New Data 03Data 02Data 03Data 04Data 05

Data ID 03New Data 03Data 02Data 03Data 04Data 05
1
Data ID 03New Data 04Data 02Data 03Data 04Data 05

Data ID 03New Data 04Data 02Data 03Data 04Data 05

Data ID 04Data 01Data 02Data 03Data 04Data 05

Data ID 05Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05

Data ID 06Data 01Data 02Data 03Data 04Data 05
3
Data ID 06New Data 08Data 02Data 03Data 04Data 05

Data ID 06New Data 08Data 02Data 03Data 04Data 05

Data ID 06New Data 08Data 02Data 03Data 04Data 05

Data ID 06New Data 08Data 02Data 03Data 04Data 05
3
Data ID 06New Data 09Data 02Data 03Data 04Data 05

Data ID 06New Data 09Data 02Data 03Data 04Data 05

Data ID 06New Data 09Data 02Data 03Data 04Data 05

Data ID 06New Data 09Data 02Data 03Data 04Data 05
3
Data ID 06New Data 10Data 02Data 03Data 04Data 05

Data ID 06New Data 10Data 02Data 03Data 04Data 05

Data ID 06New Data 10Data 02Data 03Data 04Data 05

Data ID 06New Data 10Data 02Data 03Data 04Data 05
3
Data ID 06New Data 11Data 02Data 03Data 04Data 05

Data ID 06New Data 11Data 02Data 03Data 04Data 05

Data ID 06New Data 11Data 02Data 03Data 04Data 05

Data ID 06New Data 11Data 02Data 03Data 04Data 05
3
Data ID 06New Data 12Data 02Data 03Data 04Data 05

Data ID 06New Data 12Data 02Data 03Data 04Data 05

Data ID 06New Data 12Data 02Data 03Data 04Data 05

Data ID 06New Data 12Data 02Data 03Data 04Data 05

<tbody>
</tbody>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Insert x rows
Data IDData 1Data 2Data 3Data 4Data 5
Data ID 01Data 01Data 02Data 03Data 04Data 05
Data ID 02Data 01Data 02Data 03Data 04Data 05this is after this macro has run
Data ID 03Data 01Data 02Data 03Data 04Data 05it may give you a start
Data ID 03Data 01Data 02Data 03Data 04Data 05I have no time at present to debug it
1
Data ID 03New Data 01 it is meant to add the blank rows
prior to inserting the data
1
Data ID 03New Data 02 For j = 2 To 500
If Cells(j, 1) = "" Then GoTo 100
1
Data ID 03New Data 03 For k = 1 To Cells(j, 1)
Cells(j + k, 1).Select
1
Data ID 03New Data 04 Selection.EntireRow.Insert
Next k
Data ID 04Data 01Data 02Data 03Data 04Data 05100 Next j
Data ID 05Data 01Data 02Data 03Data 04Data 05End Sub
Data ID 06Data 01Data 02Data 03Data 04Data 05
Data ID 06Data 01Data 02Data 03Data 04Data 05
Data ID 06Data 01Data 02Data 03Data 04Data 05
Data ID 06Data 01Data 02Data 03Data 04Data 05
Data ID 06New Data 08
3
Data ID 06New Data 09
3
Data ID 06New Data 10
3
Data ID 06New Data 11
3
Data ID 06New Data 12

<colgroup><col span="9"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
How about
Code:
Sub InsRws()
' fingerstyle

    Dim UsdRws As Long
    Dim Ins As Long
    Dim Rws As Long
    Dim Col As Long
    
    UsdRws = Range("B" & Rows.Count).End(xlUp).Row
    
    For Rws = UsdRws To 2 Step -1
        With Range("A" & Rws)
            If .Value <> "" Then
                Ins = .Value
                .Offset(1).Resize(Ins).EntireRow.Insert
                .Offset(, 1).Resize(Ins + 1, 6).FillDown
                .Offset(1, 1).Resize(Ins, 6).Font.Color = 45341
            End If
        End With
    Next Rws
    For Col = 4 To 7
        With Columns(Col).SpecialCells(xlBlanks)
            .Font.Color = 45341
            .Formula = "=r[-1]c"
            .Value = .Value
        End With
    Next Col

End Sub
 
Upvote 0
This works! Thank you very much. It seems to throw an error to debug at the end. With my limited (none!) knowledge of VBA coding, I couldn't decipher what it was but it did the job of inserting rows beautifully so THANK YOU, Fluff!!
 
Upvote 0
What was the error & what line of code was highlighted when you hit dubug
 
Upvote 0

Forum statistics

Threads
1,216,727
Messages
6,132,354
Members
449,720
Latest member
NJOO7

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top