I have a lengthy report I must import into Excel from a legacy Dos-based program. I can import it just fine using column width, but many of the rows have trash in them I do not want. I want to remove rows with headers, page numbers, groups of "------------", etc.
I have written this to delete the MANY empty rows (which works), but I cannot figure out how to write the part to delete the trash rows (starred lines). I am familiar with VBA in access, but this is my first attempt at using it in Excel. My GOAL is to generate rows of clean data only I can paste/import into an access database.
I have written this to delete the MANY empty rows (which works), but I cannot figure out how to write the part to delete the trash rows (starred lines). I am familiar with VBA in access, but this is my first attempt at using it in Excel. My GOAL is to generate rows of clean data only I can paste/import into an access database.
Code:
Sub DeleteEmptyRows()
'Delete Empty Rows Macro
Dim LastRow As Long, r As Long
LastRow = ActiveSheet.UsedRange.Rows.Count 'Count all the used rows in the spreadaheet
LastRow = LastRow + ActiveSheet.UsedRange.Row - 1
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If WorksheetFunction.CountA(Rows(r)) = 0 Then Rows(r).Delete
Next r 'If CountA counts Row r & finds that it has not data, it deletes it.
[COLOR="Red"]* For r = LastRow To 1 Step -1
* If r.Range("A" & X).Value = "---" Then
* r.Range("A" & X).EntireRow.Delete
* End If[/COLOR]
Next r
End Sub