Sub that does a sort gives error "You cannot change part of an array"

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
855
Office Version
  1. 365
Platform
  1. Windows
I cannot figure out what to look at to fix this issue. Sub used for sorting worked well until it did not. Now I get the error message "You cannot change part of an array" on the .Apply method. Below is the offending sub and debug.print output.

What am I doing wrong? Syntax? It must be something simple because, like I said, it worked before. I don't know of any changes to the dataset that I have made.

VBA Code:
Sub Sort_Events_Master()

    Dim rAllData As Range
    
    With [Master]
        
        Set rAllData = .Range("Header_LastName").CurrentRegion
        
Debug.Print "rAllData = " & rAllData.Address
Debug.Print "Range(Header_Event).Address = " & .Range("Header_Event").Address
Debug.Print "Range(Header_ShiftStart).Address = " & .Range("Header_ShiftStart").Address
Debug.Print "Range(Header_StartTime).Address = " & .Range("Header_StartTime").Address
Debug.Print "Range(Header_LastName).Address = " & .Range("Header_LastName").Address
    
        With .Sort
        
            .Header = xlYes
            
            .SortFields.Clear

            .SortFields.Add Key:=Range("Header_Event").Offset(1), Order:=xlAscending
            .SortFields.Add Key:=Range("Header_ShiftStart").Offset(1), Order:=xlAscending
            .SortFields.Add Key:=Range("Header_StartTime").Offset(1), Order:=xlAscending
            .SortFields.Add Key:=Range("Header_LastName").Offset(1), Order:=xlAscending
        
            .SetRange rAllData
            .Apply
        
        End With '.Sort
                
        Application.CalculateFull
        
    End With

End Sub

rAllData = $D$7:$V$107
Range(Header_Event).Address = $G$7
Range(Header_ShiftStart).Address = $J$7
Range(Header_StartTime).Address = $M$7
Range(Header_LastName).Address = $F$7
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
So, there was an array in a hidden column. I Used offset to put that array into the data table inadvertently.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,961
Messages
6,175,651
Members
452,664
Latest member
alpserbetli

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