Developer technologies | Visual Basic for Applications
An implementation of Visual Basic that is built into Microsoft products.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to delete any rows that do not start with " PDT" on all of my tabs. I'm having trouble with the VBA code and am trying to combine an if, left, and delete functions.
Dim ws As Worksheet, wb As Workbook
Dim frg As Range
For Each ws In Worksheets
ws.Activate
Set frg = Cells.Find(What:=" PDT", LookAt:=xlWhole)
If frg.Row <> 1 Then Row("A1").EntireRow.Delete
Next ws
Does someone know how to fix this?
An implementation of Visual Basic that is built into Microsoft products.
The algorithm
For Each worksheet
For Each Row
If First Column starts with 'PDT' Then
Delete Row
Maybe something like this.
Public Sub DeletePdtRows()
Dim sheet As Worksheet
Dim row As Range
For Each sheet In Me.Worksheets
For Index = 1 To sheet.Rows.Count Step 0
Dim cellValue As Range
Set cellValue = sheet.Cells(Index, 1)
If (StrComp(Left(cellValue.Value, 3), "PDT", VbCompareMethod.vbTextCompare) = 0) Then
sheet(Index).Delete (xlShiftUp)
Else
Index = Index + 1
End If
Next
Next
End Sub