Hello experts:
I'm using some VBA that automatically converts a range of data into an Excel "Table" (format). As of now, I'm using a macro and the table is properly formatted. Then I execute the macro via a "Form Control" (Button).
Dim tbl As Range
Dim ws As Worksheet
Worksheets("ConvertedData").Activate
Set tbl = Range("A1").CurrentRegion
Set ws = ActiveSheet
ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=tbl).Name = "TableTabConvertedData"
Worksheets("MasterData").Activate
Now, instead of using the Form Control's **button**, I'd prefer using an ActiveX **CommandButton** (better formatting options). However, once I execute the same code via the command button, I get the following error (see attached JPG):
The line below is highlighted:
ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=tbl).Name = "TableTabConvertedData"
Please keep in mind that the ActiveX command button resides on, e.g., sheet = "MasterData" while the Table to be formatted resides on sheet = "ConvertedData". Again, it works fine when using a macro but won't when using a command button.
My question: Given I need to format a range on a sheet which is NOT active at the time, how do I modify the code for line: "ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=tbl).Name = "TableTabConvertedData"?
Thank you,
EEH
Bookmarks