Conditionally Deleteing Rows in Multiple Columns

rchansen2001

New Member
Joined
Nov 30, 2016
Messages
28
I have the following macro which deletes rows based on the font format in column R. If the font is bold and italic then it deletes the entire row. The macro works but I am trying to modify it to include columns R:T, but I haven't figured out a way to do this. Any help is appreciated.

Code:
Sub DeleteStoppedJobs()
Dim wks As Worksheet
Dim iRow As Integer
 
    iRow = 1
 
    Set wks = Application.ActiveSheet
 
     Do Until wks.Cells(iRow, 18).Value = ""
 
        If wks.Cells(iRow, 18).Font.Bold = True And _
        wks.Cells(iRow, 18).Font.Italic = True Then
        wks.Rows(iRow).Delete
 
        Else
        iRow = iRow + 1
 
        End If
 
     Loop
 
 End Sub
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,129
Try:
Code:
Sub DeleteStoppedJobs()
    Application.ScreenUpdating = False
    Dim wks As Worksheet
    Dim i As Long
    Set wks = Application.ActiveSheet
    Dim LastRow As Long
    LastRow = wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = LastRow To 1 Step -1
        If wks.Range(Cells(i, 18), Cells(i, 20)).Font.Bold = True And wks.Range(Cells(i, 18), Cells(i, 20)).Font.Italic = True Then
            wks.Rows(i).EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
 End Sub
 
Last edited:

rchansen2001

New Member
Joined
Nov 30, 2016
Messages
28
Thank you for your response but it doesn't work exactly. Maybe I didn't explain correctly but I need it to delete the entire row if any of the columns has bold/italic font. The code you wrote only deletes the row if the font is bold/italic in all the columns (R:T) within the same row. If one of the column is not bold/italic then it doesn't delete the row.


Try:
Code:
Sub DeleteStoppedJobs()
    Application.ScreenUpdating = False
    Dim wks As Worksheet
    Dim i As Long
    Set wks = Application.ActiveSheet
    Dim LastRow As Long
    LastRow = wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = LastRow To 1 Step -1
        If wks.Range(Cells(i, 18), Cells(i, 20)).Font.Bold = True And wks.Range(Cells(i, 18), Cells(i, 20)).Font.Italic = True Then
            wks.Rows(i).EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
 End Sub
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,129
try:
Code:
Sub DeleteStoppedJobs()
    Application.ScreenUpdating = False
    Dim wks As Worksheet
    Dim i As Long
    Dim rng As Range
    Set wks = Application.ActiveSheet
    Dim LastRow As Long
    LastRow = wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = LastRow To 1 Step -1
        For Each rng In wks.Range(Cells(i, 18), Cells(i, 20))
            If rng.Font.Bold = True And rng.Font.Italic = True Then
                wks.Rows(i).EntireRow.Delete
                Exit For
            End If
        Next rng
    Next i
    Application.ScreenUpdating = True
 End Sub
 

rchansen2001

New Member
Joined
Nov 30, 2016
Messages
28
This works perfect, I even added "And rng.Font.Underline = xlUnderlineStyleSingle" as a third factor and still works.

Thank you


try:
Code:
Sub DeleteStoppedJobs()
    Application.ScreenUpdating = False
    Dim wks As Worksheet
    Dim i As Long
    Dim rng As Range
    Set wks = Application.ActiveSheet
    Dim LastRow As Long
    LastRow = wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = LastRow To 1 Step -1
        For Each rng In wks.Range(Cells(i, 18), Cells(i, 20))
            If rng.Font.Bold = True And rng.Font.Italic = True Then
                wks.Rows(i).EntireRow.Delete
                Exit For
            End If
        Next rng
    Next i
    Application.ScreenUpdating = True
 End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,842
Messages
5,598,394
Members
414,234
Latest member
grlevesq

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
Top