我是一个vba新手,我被困在应该相对容易的事情上: 我有一个marco从头文件名中指定列号:VBA编码排序数据的动态范围(列)
Dim onomata As Integer
'find column named Name of ship
Set acell = rows(1).Find(What:="Name of ship", LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not acell Is Nothing Then
onomata = acell.Column
End If
现在我想在此基础上栏我的数据进行排序:
Cells.Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range(*this is where I want to introduce the column*), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A1:AR100000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
然而,我的变量是整数,而命令请求一个范围值。任何人都可以帮助我编写代码吗?
非常感谢!它完美的工作! –
@ e-gnacio不客气 –
如果我想按照一个以上的标准排序,该怎么办?就像首先按列A然后按列B排序 –