Converting a "Delete Column" Macro to a "Delete Row" Macro
I copied the code as revised by Wouter HM and it worked as intended, without
error. It seems odd that you would get a type mismatch error on an
If...Then statement, since it only evaluates true or false. However, if you
tried to type in corrections, it might be better if you just copy the good
code and replace the one that is malfunctioning.
"cardan" wrote in message
...
On May 13, 12:53 pm, Wouter HM wrote:
Hi there
You are close.
In de code fragment Cells(a,b) the a refers to the row number and the
b refers to the column number.
Try:
Sub DeleteRows()
'
' DeleteRows Macro
'
' Keyboard Shortcut: Ctrl+Shift+F
'
Dim WS As Worksheet
Dim DeleteThese As Range
Dim LastRow As Long
Dim R As Long
For Each WS In _
Application.ActiveWindow.SelectedSheets
Set DeleteThese = Nothing
With WS
LastRow = .Cells(.Rows.Count, 1) _
.End(xlUp).Row
For R = LastRow To 1 Step -1
If .Cells(R, 1).Value = "DELETE" Then
If DeleteThese Is Nothing Then
Set DeleteThese = .Rows(R)
Else
Set DeleteThese = _
Application.Union(DeleteThese, .Rows(R))
End If
End If
Next R
If Not DeleteThese Is Nothing Then
DeleteThese.Delete
End If
End With
Next WS
End Sub
HTH,
Wouter
Hello. Thanks for the reply. I am still getting errors with this
macro. Specifically, "Run-time error '13': Type mismatch". When I
debug, it does highlight the row that you and EricG mentioned to
fix-
If .Cells(R, 1).Value = "DELETE" Then
I did correct my formula to reverse the .Cells(1, R)... to .Cells(R,
1).....
Any suggestions?
Thanks again
|