Delete Rows

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,895
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi All
This has got me confused. I'm using a Excel 97-2003 Workbook
I'm using this simple code in my workbook and get an initial Type Mismatch error "13"
On closer inspection I get the error 2042 at the Value in red.
Rich (BB code):
Sub DELROW()
Dim LR As Long, R As Long
LR = Sheets("PW").Cells(Rows.Count, "H").End(xlUp).Row
        For R = LR To 5 Step -1
            If Range("A" & R).Value = "" Then 'Value gives Error 2042
                Rows(R).EntireRow.Delete
            End If
        Next R
End Sub
It usually works fine but in this new workbook it errors out in red.
What and why am I getting an error 2042
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If you could have error values in the range try

Code:
Sub DELROW()
Dim LR As Long, R As Long
LR = Sheets("PW").Cells(Rows.Count, "H").End(xlUp).Row
        For R = LR To 5 Step -1
            If Not IsError(Range("A" & R)) Then
                If Range("A" & R).Value = "" Then 'Value gives Error 2042
                    Rows(R).EntireRow.Delete
                End If
            End If
        Next R
End Sub
 
Upvote 0
Hmm, thanks Peter
Firstly, that works !!
My question would be now....Where do the errors come from ??
There are no formulae in the cells, it's a clean worksheet, there is no other code involved
and it's never happened previously (other workbooks or sheets)
 
Upvote 0
Hmm. I don't know, sorry. I've only seen that error where there were obvious errors like #N/A.
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top