Loop Each Tab and Delete Rows

temerson

New Member
Joined
Apr 22, 2019
Messages
39
I have the following code:

Sub delete_dc_row()


Dim wbCurrent As Workbook
Dim wsCHINO As Worksheet
Dim wsSTOCKTON As Worksheet
Dim wsFLM As Worksheet
Dim wsDGV As Worksheet
Dim wsAURORA As Worksheet


Dim nLastRow, i As Integer


Set wbCurrent = ActiveWorkbook
Set wsCHINO = wbCurrent.Worksheets("CHINO")


nLastRow = wsCHINO.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row


For i = nLastRow To 12 Step -1
If InStr(1, wsCHINO.Cells(i, 6).Value, "C ", vbTextCompare) > 0 Then
Else
wsCHINO.Columns(i).Delete Shift:=xlShiftUp
End If
Next i




End Sub

The goal is to look in column F and search for and delete rows that do not contain "C ".

Thank you in advance!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
The goal is to look in column F and search for and delete rows that do not contain "C ".
Instead of looping through each individual row, you could delete them all at once by making this substitution in your code.

Code:
<del>For i = nLastRow To 12 Step -1
If InStr(1, wsCHINO.Cells(i, 6).Value, "C ", vbTextCompare) > 0 Then
Else
wsCHINO.Rows(i).Delete Shift:=xlShiftUp
End If
Next i</del>

With wsCHINO.Range("F11:F" & nLastRow)
  .AutoFilter Field:=1, Criteria1:="<>*C *"
  .Offset(1).EntireRow.Delete
  .AutoFilter Field:=1
End With

Also, if you have a very large set of data (tens of thousands of rows) a longer but faster code could be provided.
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,699
Members
452,994
Latest member
Janick

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