我录制了一个宏,然后在其中放入代码以记住活动单元格,然后即使在函数运行后也将我返回到该单元格。代码开头的Set myActiveCell = ActiveCell
和myActiveCell.Activate
的目的不是注册我的活动单元格是A14然后在运行我的排序函数后返回那里,而是注册我在A14中在函数运行之前,然后返回到该单元格(不再是A14)。我做错了什么以及如何让它正常工作?
Set myActiveCell = ActiveCell
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("K2:K600"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("B2:B600"), _SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("e2:e600")
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("C2:C600"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Data").Sort
.SetRange Range("A1:zz600")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
myActiveCell.Activate
End Sub
TIA
答案 0 :(得分:2)
如何向单元格添加注释,然后在对注释进行排序后进行搜索,如下所示:
Sub AddThenFindComment()
Dim myActiveCell As Range
Set myActiveCell = Selection
myActiveCell.AddComment "StartCell"
'OTHER CODE
Cells.Find(What:="StartCell", After:=Range("A1"), LookIn:=xlComments, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.ClearComments
End Sub