Invalid procedure call or argument

bknight
BronzeLounger
Posts: 1400
Joined: 08 Jul 2016, 18:53

Invalid procedure call or argument

Post by bknight »

I've got an older code that when run gave me an error this morning.

Code: Select all

     ActiveSheet.UsedRange.RemoveDuplicates Columns:=Array(1, 3, 4, 5, 6 _
         , 7, 8, 9, 10, 11), Header:=xlYes
Can anyone spot why this occurred and how to fix it?
Further down the code lines.

Code: Select all

        With .Font
            .Name = "Arial"
            .HorizontalAlignment = xlLeft
Object doesn't support this property or method.

User avatar
HansV
Administrator
Posts: 78544
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Invalid procedure call or argument

Post by HansV »

The code itself is OK.
Does the used range of the sheet have fewer than 11 columns? That would cause the error that you report.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78544
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Invalid procedure call or argument

Post by HansV »

HorizontalAlignment is not a property of a Font. I guess it should be

Code: Select all

        .HorizontalAlignment = xlLeft
        With .Font
            .Name = "Arial"
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1400
Joined: 08 Jul 2016, 18:53

Re: Invalid procedure call or argument

Post by bknight »

Let me count the columns and adjust if necessary. I'll move the alignment as you suggest.
Thanks