Is there a way to create a Macro to insert a blank row based on the change in cell value in multiple columns?

kokoanutt

New Member
Joined
May 17, 2024
Messages
20
Office Version
  1. 365
Platform
  1. Windows
I have already been able to create a Macro to insert a blank row based on the change in value for column C, but I also need it to look at column G. In this example, I also need a blank row in between the "ORION" and the "OCEAN" data:

1715993622442.png



Please help. Thank You!
 
Is that instead of the current line insertion when column C or G change ?
Please show us an example of how you want the output to look.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is that instead of the current line insertion when column C or G change ?
Please show us an example of how you want the output to look.
This is in addition to the blank lines that I have added when columns C and G change.

Here is an example. I only want the shaded rows to be between the two different dates containing the same value in columns C and G.
 

Attachments

  • Screenshot 2024-05-21 070930.png
    Screenshot 2024-05-21 070930.png
    76.4 KB · Views: 11
Upvote 0
See if this works for you:
VBA Code:
Sub BLANKS_SUMMARY3()

    Dim ws As Worksheet
    Dim lr As Long
    Dim i As Long
    
    Set ws = Worksheets("Logged Units Report")              'the sheet with the data
    lr = ws.Range("C" & Rows.Count).End(xlUp).Row           'last row with data in Column F
    For i = lr - 1 To 2 Step -1
        If ws.Range("C" & i).Value <> ws.Range("C" & i + 1).Value _
            Or ws.Range("G" & i).Value <> ws.Range("G" & i + 1).Value Then
                ws.Range("C" & i + 1).EntireRow.Insert
        ElseIf ws.Range("A" & i).Value2 <> ws.Range("A" & i + 1).Value2 Then
                ws.Range("A" & i + 1).EntireRow.Insert
                ws.Range("A" & i + 1).Resize(1, 7).Interior.Color = 14277081
        End If
    Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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