Need VBA solution for identifying a specific string in Column E, and deleting all the other rows that don't have that string.
FYI - Using MS Access for Remote Automation of an Excel Workbook
The code below was designed to open the workbook with a CSV converted file of over 1,000,000 rows (2 to the 10th power)
The code ran for 15 minutes but only deleted around 10,000 rows. (works correct, but way, way too slow)
The data dumps of over 1,000,000 rows once filtered will end up with about 12,000 rows on average.
This is saved as, and used in the next business process.
Tried to record a macro. created a filter on Row A (header) then on Column E - Text Filter Does not contain "SENG"
Then highlighted all of the rows and deleted them. Turn off filter. Problem is that all of the empty rows still exist!
</csv></add>
FYI - Using MS Access for Remote Automation of an Excel Workbook
The code below was designed to open the workbook with a CSV converted file of over 1,000,000 rows (2 to the 10th power)
The code ran for 15 minutes but only deleted around 10,000 rows. (works correct, but way, way too slow)
The data dumps of over 1,000,000 rows once filtered will end up with about 12,000 rows on average.
This is saved as, and used in the next business process.
Tried to record a macro. created a filter on Row A (header) then on Column E - Text Filter Does not contain "SENG"
Then highlighted all of the rows and deleted them. Turn off filter. Problem is that all of the empty rows still exist!
Code:
Public Sub OpenExcelWorkbookforAutomationFilterAndSave()
Dim Objxl As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSh As Excel.Worksheet
Dim LR As Long
Dim CSVRawFileName As String
' this is hardcoded for testing - add as parameter later
CSVRawFileName = "C:\Users\UserName\ExcelTesting\CAPEX Transaction Details.xlsx"
Set Objxl = New Excel.Application
Set xlWB = Objxl.Workbooks.Open(CSVRawFileName) '<add user="" function="" Environ="" in="" PC
Set xlSh = xlWB.Sheets(1) '<csv 1="" has="" file="" worksheet
'Remote code
Objxl.ScreenUpdating = False
With xlSh
For LR = .Range("E" & .Rows.Count).End(xlUp).Row To 2 Step -1
If Trim(Range("E" & LR).Value) <> "SENG" Then
.Rows(LR).EntireRow.Delete
Else
Debug.Print "found " & Trim(Range("E" & LR).Value) ' Expect 12,000 rows of the over 1,000,000
End If
Next LR
End With
Objxl.ScreenUpdating = True
xlWB.SaveAs FileName:= _
"C:\Users\UserName\Desktop\ExcelTesting\CAPEX Transaction DetailCulled.xlsx" _
, CreateBackup:=False
xlWB.Save
xlWB.Close
Objxl.Quit
Set Objxl = Nothing
End Sub