Code works with control button but not with Activate sheet

Alex B

New Member
Joined
Jan 22, 2015
Messages
12
Hi,

I run this script with a button within a worksheet:

Code:
Sub updatepersonnellist()
   
   Application.Calculation = xlCalculationManual
    
    Application.ScreenUpdating = False
        
    Sheets("Resurstid").Visible = True
        
    Sheets("Resurstid").Select
    Columns("A:F").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "H1:M2"), CopyToRange:=Range("H4"), Unique:=True
        
    Sheets("Analys per konsult").Select

                With Sheets("Analys per konsult")


            With .Range("B15:N1000")
            .Clear
            End With

           Dim lastRow2 As Long
            lastRow2 = Sheets("Resurstid").Range("H" & Rows.Count).End(xlUp).Row + 7
            Sheets("Analys per konsult").Range("B12:N12").Copy Sheets("Analys per konsult").Range("B13:N" & lastRow2)
            End With

   Sheets("Resurstid").Visible = False

   Application.Calculation = xlCalculationAutomatic
        
End Sub

With the button, the code works as I want it to. Now I´m trying to put the code in the same worksheets Activate procedure, but then I get the error message: "Run time error 1004: We can´t do that to a merged cell", and the following part of the code is marked:

Code:
    Columns("A:F").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "H1:M2"), CopyToRange:=Range("H4"), Unique:=True

In the sheet where the advanced filter is done, there are no merged cells.

Any suggestions on what I´m doing wrong?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,217,371
Messages
6,136,176
Members
449,996
Latest member
duraichandra

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