excel vba to insert black row in filtered data

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hey guys, I'm trying to create a vba which inserts a blank color filled row above every cell in Column B which contains the text "BASE".

pseudo code:
if cell contains "BASE"
then insert blank row above and fill the whole row in Black
else move on to next cell
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this:
Code:
Sub InsertBlackRows()

    Dim myRow As Long
    Dim lastRow As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column B
    lastRow = Cells(Rows.Count, "B").End(xlUp).Row

'   Loop through all rows in column B backwards
    For myRow = lastRow To 1 Step -1
        If UCase(Cells(myRow, "B")) = "BASE" Then
            Rows(myRow).Insert
            With Rows(myRow).Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .ThemeColor = xlThemeColorLight1
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
        End If
    Next myRow
        
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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