melodramatic
Board Regular
- Joined
- Apr 28, 2003
- Messages
- 180
- Office Version
- 365
- Platform
- Windows
I have created a macro that, after an editor finishes their edits and is ready to re-protect them, goes through each data sheet, sorts the table, protects and hides the sheet. It then goes on to the next sheet/table on the list.
The problem I'm having is in using the variable table name in the sort feature.
When I first created the macro, I did my norm and went thru the steps, using the first sheet/table in the list. Here's what it gave me...
When I went to run that coding with the variables, I made the following line, which does NOT work:
I get "Compile error: Type-declaration character does not match declared data type"
I've also tried the following (I found it somewhere online...), which gives me a Run-time error 1004: Method 'Range' of object '_Worksheet' failed
I'm at the give up and ask for help point. Does anyone have an idea as to how I can do this? Thanks in advance!
The problem I'm having is in using the variable table name in the sort feature.
When I first created the macro, I did my norm and went thru the steps, using the first sheet/table in the list. Here's what it gave me...
Code:
ActiveWorkbook.Worksheets("KCO US").ListObjects("T_KCO_US").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("KCO US").ListObjects("T_KCO_US").Sort.SortFields. _
Add2 Key:=Range("T_KCO_US[[#All],[EFFECTIVE DATE]]"), _ 'THIS IS THE LINE THAT'S GIVING ME PROBLEMS W/VARIABLE NAME USE
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("KCO US").ListObjects("T_KCO_US").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
When I went to run that coding with the variables, I made the following line, which does NOT work:
Code:
Add2 Key:=Range(t_name&("[[#All],[EFFECTIVE DATE]]")), _
I get "Compile error: Type-declaration character does not match declared data type"
I've also tried the following (I found it somewhere online...), which gives me a Run-time error 1004: Method 'Range' of object '_Worksheet' failed
Code:
Add2 Key:=Range(t_name & "[EFFECTIVE DATE]"), _
Code:
Add2Key:=Range(t_name&"[[#All],[EFFECTIVE DATE]]"), _
I'm at the give up and ask for help point. Does anyone have an idea as to how I can do this? Thanks in advance!