【发布时间】:2018-04-05 20:36:02
【问题描述】:
我们提供了一个 excel-vba 文件,它在某些机器上运行良好,但在某些机器上会生成以下错误:运行时错误 1004,应用程序定义或用户定义错误,顺序如下:
sheetChoiceList.Sort.SortFields.Add key:=ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange.Columns(6), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
子:
Sub SortChoiceListForCurrentQuestionChoiceList()
' Sorts the Choice List based on the question type of the current question
' A formula in the sheet determines if the choice is applicable to the current question, returning a TRUE/FALSE
' A dyanamic named range uses the count of TRUE values to determine the number of rows extending down from row 2
' The sort is necessary to ensure that the TRUE values start on row 2
sheetChoiceList.Sort.SortFields.Clear
sheetChoiceList.Sort.SortFields.Add key:=ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange.Columns(6), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With sheetChoiceList.Sort
.SetRange ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
【问题讨论】: