Forum Discussion

seanrm100_'s avatar
seanrm100_
Copper Contributor
Sep 27, 2019
Solved

Mystery error happens randomly, but more often when running from a formcontrol button...

So I have a macro that creates sheets, transfers data to them, and then cleans it. All is well and good, but I often get the 'Runtime Error 1004: The sort reference isn't valid. Make sure that it'...
  • seanrm100_ 

    You should qualify the key with the Sheet reference like this...

    ws.Range("A1:Z200").Sort Key1:=ws.Columns("A"), Order1:=xlAscending, Header:=xlNo

     

    Or more precisely this...

    ws.Range("A1:Z200").Sort Key1:=ws.Range("A1"), Order1:=xlAscending, Header:=xlNo

     

    This should resolve the issue.

Resources