Hi there,
I’ve been using the below code for some time to delete unwanted (grand total) rows from an often updated document:
Sub DeleteRows()
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
Dim rng As Range, cell As Range, del As Range
Set rng = Range("RowRemoval")
For Each cell In rng
If (cell.Value) = "Grand Total" _
Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
End Sub
It has been working fine for a number of weeks, however, when attempting to utilise it in another workbook (copied the module over exactly) I get the error message:
““Run-time error ‘1004’:
Method ‘Range’ of object ‘ _ Global’ failed”
And the: Set rng = Range("RowRemoval") is highlighted yellow.
It seems I am not designating my ranges correctly, but I cannot work out why it works in my previous workbook but not this one. Any recommended code or advice would be very much appreciated.
John
I’ve been using the below code for some time to delete unwanted (grand total) rows from an often updated document:
Sub DeleteRows()
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
Dim rng As Range, cell As Range, del As Range
Set rng = Range("RowRemoval")
For Each cell In rng
If (cell.Value) = "Grand Total" _
Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
End Sub
It has been working fine for a number of weeks, however, when attempting to utilise it in another workbook (copied the module over exactly) I get the error message:
““Run-time error ‘1004’:
Method ‘Range’ of object ‘ _ Global’ failed”
And the: Set rng = Range("RowRemoval") is highlighted yellow.
It seems I am not designating my ranges correctly, but I cannot work out why it works in my previous workbook but not this one. Any recommended code or advice would be very much appreciated.
John