Usedrange adding range that is not used

Afro_Cookie

Board Regular
Joined
Mar 17, 2020
Messages
103
Office Version
  1. 365
Platform
  1. Windows
There's a portion of my code I use to cut and paste the used range from one sheet to another. Recently it's started adding extra lines into the used range which is affecting my table by adding blank lines. This is mildly inconvenient as I have to manually delete the lines, but it's not supposed to add them in the first place.

Any advice on how to correct or tweek my code/trouble shoot this?

This is just a portion of the code.
VBA Code:
' Remove Duplicates

    ActiveSheet.Range("A:I").RemoveDuplicates Columns:=Array(4, 6, 7), Header:=xlNo

'paste used range after ducplicates are removed

    ActiveSheet.UsedRange.Select
    
    Selection.Cut
    Sheets("abcd").Select
    Range("A" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
    ActiveSheet.Paste

So right now that code should cut and paste 6 lines, but it is taking 10 instead and I have no idea why.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
"UsedRange" is not all that reliable. If you delete rows, like your code is doing, it does NOT reset the UserRange.
There are other ways to find the last cell. See: Find last row, column or last cell

If there are no completely blank rows/columns in the middle of your data, you may be able to use CurrentRegion, i.e.
ActiveSheet.Range("A1").CurrentRegion.Select
Otherwise, use one of the other methods mentioned in the link.
 
Upvote 0
Switched the UsedRange to CurrentRegion. Worked perfectly. Thanks.

"UsedRange" is not all that reliable. If you delete rows, like your code is doing, it does NOT reset the UserRange.
There are other ways to find the last cell. See: Find last row, column or last cell

If there are no completely blank rows/columns in the middle of your data, you may be able to use CurrentRegion, i.e.
ActiveSheet.Range("A1").CurrentRegion.Select
Otherwise, use one of the other methods mentioned in the link.
 
Upvote 0

Forum statistics

Threads
1,214,581
Messages
6,120,368
Members
448,957
Latest member
BatCoder

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