Results 1 to 7 of 7

VBA Run-time error 1004

Threaded View

skydivetom VBA Run-time error 1004 06-24-2020, 12:59 PM
Fluff13 Re: VBA Run-time error 1004 06-24-2020, 01:27 PM
Marc L Re: VBA Run-time error 1004 06-24-2020, 01:28 PM
AlphaFrog Re: VBA Run-time error 1004 06-24-2020, 01:28 PM
dangelor Re: VBA Run-time error 1004 06-24-2020, 01:32 PM
skydivetom Re: VBA Run-time error 1004 06-24-2020, 01:42 PM
Fluff13 Re: VBA Run-time error 1004 06-24-2020, 01:42 PM
  1. #1
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    367

    VBA Run-time error 1004

    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
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] I am getting error as "Run Time error '1004' Microsoft excel cannot paste the data
    By Amittapre in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 03-24-2017, 04:40 PM
  2. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  3. Addon error : Run-time error '1004': Method 'MacroOptions' of object '_Application' failed
    By jtcoleman in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-05-2014, 12:23 PM
  4. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  5. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  6. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  7. run-time error '1004': Application-defined or object-deifined error
    By rich5665@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1