为什么这个工作:排序键范围查询
Range(Cells(1, 1), Cells(5, 5)).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
但这并不?:
Range(Cells(1, 1), Cells(5, 5)).Select
Selection.Sort Key1:=Range(Cells(1,1)), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
话说
法范围失败
编辑
之所以问的是,我想那种关键是动态的,如:
Selection.Sort Key1:=Range(Cells(intRow, intCol))
我看不出如何做到这一点。
因为'范围'本身并不意味着在这种情况下任何东西。尝试在你的第二行改变'Range(Cells(1,1)'到'Selection(Cells(1,1))'这并不是最佳实践,但至少你将'Cells'属性绑定到这个对象中最好的做法是始终限定您的范围,单元格,表单等 –
感谢但选择提供了一种类型不匹配,我添加了一个编辑 – RGriffiths
所以只需使用'Key1:= Cells(intRow,intCol)' –