Iam New to Excel VBA.I tend to sort an column in a Table Using VBA code. My Table Name will be dynamic. So a string is created.
Sub Macro3()
‘
‘ Macro3 Macro
‘
‘
Dim TN As String
Range("A11").Select
TN = ActiveCell.ListObject.Name
ActiveWorkbook.Worksheets("Base Unit").ListObjects(TN).Sort.SortFields _
.Clear
ActiveWorkbook.Worksheets("Base Unit").ListObjects(TN).Sort.SortFields _
.Add2 Key:=Range("Base_Unit[[#All],[Cabinet Number]]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Base Unit").ListObjects(TN).Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I Want to Give A String to .Add2 Key Range
.Add2 Key:=Range(“Base_Unit[[#All],[Cabinet Number]]”),
Is It Possible .
I tried to give a name to the Key Range . But error Occurs
New contributor
guganeshan mahalingam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.