I am trying to create a table on a different sheet that is not my Activesheet using a button. This is my code so far; the problem area is in between the asterisks.
I think it has something to do with "ActiveSheet" because when this part of the code is executed the command isn't happening on the Active sheet, but rather a different sheet called "Competitor Overview Data". I have tried to play around with it but I haven't been able to figure out why I cant create a table on a different sheet.
Code:
Private Sub CommandButton1_Click()
Set srtA = Sheets("Competitor Comparison")
With srtA
.ListObjects(1).Unlist
Range("DynamicCompList").Sort Key1:=Range("DynamicCompList"), Order1:=xlAscending, Header:=xlYes, Orientation:=xlLeftToRight
ActiveSheet.ListObjects.Add(xlSrcRange, Range("DynamicCompTable"), , xlYes).Name = _
"CompComparisonTable"
Range("A8").Select
Selection.AutoFilter
End With
Set srtB = Sheets("Competitor Comparison Data")
With srtB
.Range("DynamicDataList").Sort Key1:=.Range("DynamicDataList"), Order1:=xlAscending, Header:=xlYes, Orientation:=xlLeftToRight
End With
'*********************************************************
Set srtC = Sheets("Competitor Overview Data")
With srtC
.ListObjects(2).Unlist
.Range("CODSort").Sort Key1:=.Range("CODSort"), Order1:=xlAscending, Header:=xlGuess, Orientation:=xlLeftToRight
ActiveSheet.ListObjects.Add(xlSrcRange, Range("CODTable"), , xlYes).Name = _
"CompOverviewTable"
Range("E6").Select
Selection.AutoFilter
End With
End Sub
'*********************************************************
I think it has something to do with "ActiveSheet" because when this part of the code is executed the command isn't happening on the Active sheet, but rather a different sheet called "Competitor Overview Data". I have tried to play around with it but I haven't been able to figure out why I cant create a table on a different sheet.