![]() |
Expected:expression
I tryed that and now I get the following error:
Compile error Syntax error I would appericiate any further help. Thanks. -----Original Message----- Change Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending to Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8"), Order1:= xlAscending -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Capinvest" wrote in message ... I am trying to sort a combobox alphabetically in excel using vba. I have the following code behind the combobox: Private Sub ClientList_Change() ' this sorts the names alphabetically Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending End Sub I get an error everytime I try to run it. The error says: Compile error: Expected:expression I would appericate any help with this issue. . |
Expected:expression
is the code really on three lines. If so, you would use line continuation
characters: Worksheets("Home").Range("C8:C27").Sort _ Key1: = Worksheets("Home").Range("C8"), _ Order1:= xlAscending Also, you might need to clear the rowsource/listfillrange of the control before sorting Public bBlockEvents as Boolean Assuming on a worksheet, for a userform change listfillrange to rowsource Private Sub ClientList_Change() ' this sorts the names alphabetically if bBlockEvents then exit sub On Error goto ErrHandler bBlockEvents = True ClientList.ListFillRange = "" Worksheets("Home").Range("C8:C27").Sort _ Key1: = Worksheets("Home").Range("C8"), _ Order1:= xlAscending ClientList.ListFillRange = "Home!C8:C27" ErrHandler: bBlockEvents = False End Sub Still, I am not sure why you would sort the list on a change event. Also, making changes like this in the change event (which would trigger a change event) can be troublesome. The above is untested and may not work anyway. -- Regards, Tom Ogilvy "Capinvest" wrote in message ... I tryed that and now I get the following error: Compile error Syntax error I would appericiate any further help. Thanks. -----Original Message----- Change Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending to Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8"), Order1:= xlAscending -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Capinvest" wrote in message ... I am trying to sort a combobox alphabetically in excel using vba. I have the following code behind the combobox: Private Sub ClientList_Change() ' this sorts the names alphabetically Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending End Sub I get an error everytime I try to run it. The error says: Compile error: Expected:expression I would appericate any help with this issue. . |
Expected:expression
Thanks for your help, everything works great.
-----Original Message----- is the code really on three lines. If so, you would use line continuation characters: Worksheets("Home").Range("C8:C27").Sort _ Key1: = Worksheets("Home").Range("C8"), _ Order1:= xlAscending Also, you might need to clear the rowsource/listfillrange of the control before sorting Public bBlockEvents as Boolean Assuming on a worksheet, for a userform change listfillrange to rowsource Private Sub ClientList_Change() ' this sorts the names alphabetically if bBlockEvents then exit sub On Error goto ErrHandler bBlockEvents = True ClientList.ListFillRange = "" Worksheets("Home").Range("C8:C27").Sort _ Key1: = Worksheets("Home").Range("C8"), _ Order1:= xlAscending ClientList.ListFillRange = "Home!C8:C27" ErrHandler: bBlockEvents = False End Sub Still, I am not sure why you would sort the list on a change event. Also, making changes like this in the change event (which would trigger a change event) can be troublesome. The above is untested and may not work anyway. -- Regards, Tom Ogilvy "Capinvest" wrote in message ... I tryed that and now I get the following error: Compile error Syntax error I would appericiate any further help. Thanks. -----Original Message----- Change Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending to Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8"), Order1:= xlAscending -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Capinvest" wrote in message ... I am trying to sort a combobox alphabetically in excel using vba. I have the following code behind the combobox: Private Sub ClientList_Change() ' this sorts the names alphabetically Worksheets("Home").Range("C8:C27").Sort Key1: = Worksheets("Home").Range("C8") XlSortOrder.xlAscending End Sub I get an error everytime I try to run it. The error says: Compile error: Expected:expression I would appericate any help with this issue. . . |
All times are GMT +1. The time now is 12:09 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com