Loop Through Table to Delete Unwanted Rows of Data

ChuckFerrera

New Member
Joined
Jun 1, 2015
Messages
2
Hello,

I am currently working on an automation project where I am receiving raw data of the parts in our inventory. I am then wanting to sort through the raw data to delete the unwanted rows of data, and then compare that "filtered" data to a set list of needed part numbers. The below loop is what I am currently using, but it is not deleting any rows of data.

Code:
[COLOR=#ff8c00]'Loop Through & Count Number of Rows of PLCX[/COLOR]
[COLOR=#0000cd]Do Until IsEmpty(ActiveCell)[/COLOR]
         
         [COLOR=#ff8c00]' Step down 1 row from present location.[/COLOR]
         [COLOR=#0000cd]ActiveCell.Offset(1, 0).Select
         
         If ActiveCell.Value Like "E ,2*" Or ActiveCell.Value <> "E, 2*" Or ActiveCell.Value <> "E,2*" Or ActiveCell.Value <> "E .2*" Or ActiveCell.Value <> "E. 2*" Or ActiveCell.Value <> "E.2*" Then
         
         PLCXRowCount = PLCXRowCount + 1
         
         Else
         
         Rows(ActiveCell.Row).EntireRow.Delete
                  
         End If
                       
      Loop[/COLOR]

Thanks in advance for any help you can provide!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
FYI, I am undoubtedly a noob to VBA.

I have now attempted to use a dynamic array to sort the data and have changed my code up to look like this.

Code:
Dim PLCXRowCount As Long
Dim PNRowCount As Long
Dim PLCXAvailCtr As Long
Dim PLCXAvail() As String, PLCXPN As String, PLCXQty As Long, PLCXLocation As String
Dim PLCXDataSheetName As String
Dim PLCXTableSheetName As String
Dim PLCXPivotTableName As String


[COLOR=#ff8c00]'Set Row Count[/COLOR]
PLCXRowCount = 0
PLCXRowCount = WorksheetFunction.CountA(Worksheets("PLCX").Columns(1)) - 2


[COLOR=#FF8C00]'Redimension Array[/COLOR]
ReDim PLCXAvail(PLCXRowCount, 2)


[COLOR=#FF8C00]'Select PLCX Worksheet[/COLOR]
Worksheets("PLCX").Select
Range("A1").Select


[COLOR=#FF8C00]'Save PLCX Data to Array[/COLOR]
For PLCXAvailCtr = 0 To PNRowCount


    If Range("D" & (PLCXAvailCtr + 2)) = "E ,2*" Or "E, 2*" Or "E,2*" Or "E .2*" Or "E. 2*" Or "E.2*" Then
    
            PLCXAvail(PLCXAvailCtr, 0) = Range("A" & (PLCXAvailCtr + 2))
            PLCXAvail(PLCXAvailCtr, 1) = Range("C" & (PLCXAvailCtr + 2))
            PLCXAvail(PLCXAvailCtr, 2) = Range("D" & (PLCXAvailCtr + 2))
        
        Else
        
            PLCXAvail(PLCXAvailCtr, 0) = "-"
            PLCXAvail(PLCXAvailCtr, 1) = "0"
            PLCXAvail(PLCXAvailCtr, 2) = "-"
    
    End If
    
Next PLCXAvailCtr

I am now getting a Run-time error of "13" and the explanation of "Type Mismatch." I cannot figure out why I am getting this error because both of the values I am comparing are strings. I would greatly appreciate any help that you can provide.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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