Hi, Apologies if i am making a mistake or not following some proper protocols to post here. I am new to the forum and new to VBA but I am a quick learner.
Need to ask if there is a way (without defining a variable) to replace the hard coded key range in the following code? I have a worksheet called "Sheet1" and a table in there defined as "Table1". So how do I use the listobjects/listcolumns to simply say that the key range is column("Col7") for example.
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort.SortFields.Add _
Key:=Range("S2:S160"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
Need to ask if there is a way (without defining a variable) to replace the hard coded key range in the following code? I have a worksheet called "Sheet1" and a table in there defined as "Table1". So how do I use the listobjects/listcolumns to simply say that the key range is column("Col7") for example.
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort.SortFields.Add _
Key:=Range("S2:S160"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply