B
bevinb
Hi, I know little about VBA but know a macro can really speed up a
tedious weekly task, if only I can figure out how to write it.
What I need: I have a report imported into Excel. This report
contains several headers that are repeated throughout and I want to
delete those rows. From browsing the newsgroup I found this sample
code:
Public Sub SelectiveDelete()
Dim LRowData As Long, ir As Long
With Sheets("Sheet1")
' detect last row of data in column A
LRowData = .Cells(Rows.Count, "A").End(xlUp).Row
' scan list testing if the value is in range
For ir = LRowData To 1 Step -1
If Trim(.Cells(ir, 1).Value) = "A/C No" Or _
Trim(.Cells(ir, 1).Value) = "Report Total" Or _
InStr(1, Trim(.Cells(ir, 2).Value), "@") > 0 Or _
Len(Trim(.Cells(ir, 2).Value)) = 0 _
Then .Rows(ir).Delete Shift:=xlUp
Next ir
End With
End Sub
This works except that I will need to add more Value Lines with my
criteria; I know how to do that.
However, I do not need to look for anything in Column B yet if I get
rid of those lines, it comes up with a syntax error. What do I need
for the last three lines if all I want is to delete rows that have
specific values in Column A as in the two lines with Trim....
Also, it appears that one of the rows that is imported that I want to
delete has a character that looks like a check box in it (and that is
all) Anyone know how to type this in Excel?
Thanks for any help, Bevin B.
tedious weekly task, if only I can figure out how to write it.
What I need: I have a report imported into Excel. This report
contains several headers that are repeated throughout and I want to
delete those rows. From browsing the newsgroup I found this sample
code:
Public Sub SelectiveDelete()
Dim LRowData As Long, ir As Long
With Sheets("Sheet1")
' detect last row of data in column A
LRowData = .Cells(Rows.Count, "A").End(xlUp).Row
' scan list testing if the value is in range
For ir = LRowData To 1 Step -1
If Trim(.Cells(ir, 1).Value) = "A/C No" Or _
Trim(.Cells(ir, 1).Value) = "Report Total" Or _
InStr(1, Trim(.Cells(ir, 2).Value), "@") > 0 Or _
Len(Trim(.Cells(ir, 2).Value)) = 0 _
Then .Rows(ir).Delete Shift:=xlUp
Next ir
End With
End Sub
This works except that I will need to add more Value Lines with my
criteria; I know how to do that.
However, I do not need to look for anything in Column B yet if I get
rid of those lines, it comes up with a syntax error. What do I need
for the last three lines if all I want is to delete rows that have
specific values in Column A as in the two lines with Trim....
Also, it appears that one of the rows that is imported that I want to
delete has a character that looks like a check box in it (and that is
all) Anyone know how to type this in Excel?
Thanks for any help, Bevin B.