none
range.sort syntax RRS feed

  • Question

  • We have VBA program to run in Excel 2016 for Windows and Mac.

    In Excel 2016 for Windows, below syntax is working fine and we can sort the value successfully

     With objDestWorkSheet
     .Activate

     .Range("$A$7:$DF$" & intLastRow).Sort key1:=objDestWorkSheet.Range("C7"), order1:=xlDescending, Header:=xlYes

    End With

    In Excel 2016 for Mac, above syntax is not working and error "Run-time error 91 . Object variable or With block variable not set".

    Can you please kindly help ?

    Thursday, December 8, 2016 3:39 AM

All replies

  • I presume you have already used the line:

        Set objDestWorkSheet = Excel.activesheet
       ' or Set objDestWorkSheet = Excel.thisworkbook.sheets("Sheet1")   ' or the name of the worksheet you are targeting

    Also: intLastRow must be >=1


    -MainSleuth


    • Edited by MainSleuth Thursday, December 8, 2016 4:31 AM clarity
    Thursday, December 8, 2016 4:29 AM
  • We've already set ObjDestWorkSheet as current Activate worksheet and intLastRow is greater than 1

    Above syntax is working fine in Excel 2016 for Windows but not for Macintosh

    Thursday, December 8, 2016 6:45 AM
  • Hi,

    Thanks for posting here.

    For issue about Office for Mac, I suggest you ask in https://answers.microsoft.com/en-us/msoffice.

    This forum is for Windows OS, we don’t have MacOS to reproduce and test your issue. The supporters on Microsoft Community might offer better suggestions for you.

    Sorry for any inconvenience and have a nice day! 

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 9, 2016 8:27 AM
    Moderator