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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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