Insert a blanc row at a data change in column - office 365 dutch

charlottedv

New Member
Joined
May 14, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi!
I'm trying to add a blanc row everytime there's a change in data in one of my columns.
I've read already some other threads with similar questions like: Thread 1 and Thread 2 but none of the codes mentioned here seem to work for me.
I get the error: "types do not match". Could it have to do with the fact that my office language is set in Dutch? (belgian user here 🙋‍♀️)

In this image you can see the basic set up of my data sheet.
I would need a blanc row everytime the column "Variantcode" changes.
Any solution or help to automate this proces is welcome, VBA or basic excel actions.
1715686393697.png
 
Try this:
VBA Code:
Sub MyInsertBlankRows()

    Dim lr As Long
    Dim r As Long
   
    On Error GoTo err_chk
   
    Application.ScreenUpdating = False
   
'   Find last row in column Z with data
    lr = Cells(Rows.Count, "Z").End(xlUp).Row
   
'   Loop through all rows starting from bottom up to row 3
    For r = lr To 3 Step -1
'       Check to see if value is different from row above
        If Cells(r, "Z") <> Cells(r - 1, "Z") Then
'           Insert blank rows
            Rows(r).Insert
'           Populate values in new row
            Cells(r, "E") = Cells(r + 1, "E")
            Cells(r, "G") = "matrix"
            Cells(r, "H") = Cells(r + 1, "H")
            Cells(r, "K") = Cells(r + 1, "K")
            Cells(r, "L") = Cells(r + 1, "L")
            Cells(r, "M") = Cells(r + 1, "M")
            Cells(r, "Z") = Cells(r + 1, "Z")
            Cells(r, "Y") = Cells(r, "Z")
        End If
    Next r
   
    Application.ScreenUpdating = True
   
    Exit Sub
   
err_chk:
    If Err.Number = 13 Then
        MsgBox "Error is near line " & r
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
   
    Application.ScreenUpdating = True
   
End Sub
This works perfectly, thank you!
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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