Macro errors out when run automatically, but no problem when step-by-step

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
367
Office Version
  1. 2019
I have a large macro that begins by copying a range to a Temp sheet and removing the duplicates to begin processing the data.
If I run the macro with an assigned button (or F5) it errors out due to encountering blank cells in the Temp sheets after the remove duplicates operation. Looking in the Temp sheet after the code stops, I see that there are 10 blank lines (or cells - I can't tell due to only column A having data at this stage) inserted about 3/4 of the way down my list.
If I put a break point on the remove duplicates line, the code stops and shows me the list that was copied to the clipboard, which correctly contains no blanks at all, and the pasted list on the Temp sheet also contains no blanks at all. If I press F8 on the remove duplicates line, the list is condensed just as it should be, with no blanks.

To summarise: the following line ends up with blanks in the list if pressing F5, but correctly has no blanks if pressing F8
VBA Code:
Xero.Sheets("Temp").Range("$A$1:A" & Cells(Rows.Count, "A").End(xlUp).Row).RemoveDuplicates Columns:=1, Header:=xlNo

Attached is a screenshot of the input and outputs.
I have been using this macro for months and never encountered this problem, but now it occurs on both my Win10/Excel 2019 machine and my Win11/365 machine.

What is going wrong?
 

Attachments

  • Screenshot 2024-08-13 202401.png
    Screenshot 2024-08-13 202401.png
    46.8 KB · Views: 23

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Does it make any difference if you do this:
(this explicitly qualifies the .Cells(Rows.Count,"A") )

VBA Code:
With Xero.Sheets("Temp")
    .Range("$A$1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).RemoveDuplicates Columns:=1, Header:=xlNo
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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