type mismatch when deleting rows

bleeet

Board Regular
Joined
May 11, 2009
Messages
208
Office Version
  1. 2013
Platform
  1. Windows
Hi guys I am trying to figure out why I am getting a type mismatch when deleting rows past a certain number.

Well I am not sure if this is because its a large number of rows but here is the code I use.

With Worksheets("PWPCP")
Rows("6:" & .UsedRange.Count).Delete
End With

I made this to delete all the data in rows 6 and below but its giving me a type mismatch error and I am not sure how to fix this.

thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
.UsedRange.Count returns the total cell count for the used range, not the row count. Try:

.UsedRange.Rows.Count
 
Upvote 0
Because you are not counting all the rows, but rather all the cells (which probably is more than the number of possible rows on the sheet!).
Also, I think you need a period in front of "Rows".
Try:
Code:
[COLOR=#333333]With Worksheets("PWPCP")[/COLOR]
[COLOR=#333333]    .Rows("6:" & .UsedRange.Rows.Count).Delete[/COLOR]
[COLOR=#333333]End With[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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