excel vba to insert black row in filtered data

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
144
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,481
Office Version
365
Platform
Windows
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,481
Office Version
365
Platform
Windows
You are welcome!:)
 

Forum statistics

Threads
1,082,044
Messages
5,362,843
Members
400,694
Latest member
Sofie17

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top