+ Reply to Thread
Results 1 to 7 of 7

Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into it?

  1. #1
    Registered User
    Join Date
    11-22-2014
    Location
    Wirral, UK
    MS-Off Ver
    Office 2007
    Posts
    6

    Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into it?

    I have a process which maps columns from one sheet to another within the same workbook driven by a Field (/Column) mapping table.
    The table contains source column number and name and target column number and name.
    Earlier versions of code used a combination of range/cells notation to successfully map from input to output.
    As the target table is ultimately defined as a ListObject I thought about having the transfer code:
    1. Use conventional Range techniques to add and copy in the first column.
    2. Based on this single column range, create and name a ListObject.
    3. Thereafter add a new column (via ListColumns(n).add)
    4. Give the new column a name
    5. Copy using ListColumns.DataBodyRange references for both source and target columns copy or Copy/Paste the data to the new column

    The process fails at stage 5. I have checked the column references in 'Locals' and using 'mouse-over'.
    The defined listobject target table in the physical sheet is recognised and the column named as expected. It is in Column 2 as expected.
    There MAY be something missing in the syntax and have tried an extra .Range but to no avail.

    Code snippet:
    Please Login or Register  to view this content.
    Hope someone out there can help
    NDG1944
    Last edited by NDG1944; 02-22-2018 at 01:57 PM. Reason: Run Time error 438

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    Where exactly does it fail in the posted code and what's the error message?

    Does this work?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-22-2014
    Location
    Wirral, UK
    MS-Off Ver
    Office 2007
    Posts
    6

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    Norie,
    Sorry, I got pre-occupied with the narrative.
    Ref my original code snippet; that failed with "Run-Time error '438': Object doesn't support this property or method" invariably on the 'Destination' side of the Copy or Copy/Paste.
    The Copy stage of the Copy/Paste combination works in VBA AND shows the column with the 'selected' border on the source sheet.
    Ref your suggestion: I think that this was my first attempt perhaps using strTargetColName rather than intTargetColno.
    I have also tried your suggestion previously; this looks the most compact and perhaps speediest method but I haven't got far enough to assess efficiency.
    I can't remember if I used an intermediate ListColumn object and worked the copy to that target object.
    Regards, Nigel
    Last edited by NDG1944; 02-22-2018 at 05:15 PM. Reason: Change ListRow to ListColumn

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    Nigel

    I did some testing, albeit with simple tables/data etc, and the code I suggested appeared to work.

    If you attached a sample workbook with representative data I could look into it further.

    PS When I originally saw the thread my first thought was to copy the data and then create the table.

  5. #5
    Registered User
    Join Date
    11-22-2014
    Location
    Wirral, UK
    MS-Off Ver
    Office 2007
    Posts
    6

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    Hi Norie,
    Would it be appropriate for you to supply your sample data and code. I am working on live data and by the time I have sanitised it we could be into next week! I know what you have suggested SHOULD work but for some reason doesn't.
    Your PS identifies the way I addressed the task initially but having seen some very complex ways of achieving this or similar, the brevity and self-documentation associated with ListObjects is far more appealing and easier to debug (subject to this issue). I have even used the 'CreateNames' method in previous iterations which was cumbersome. The only approach that I have not tried is 'structured references' but they look clumsy to build dynamically.
    Regards,
    Nigel

  6. #6
    Registered User
    Join Date
    11-22-2014
    Location
    Wirral, UK
    MS-Off Ver
    Office 2007
    Posts
    6

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    Hi Norie,
    Still not sure about the failure of the original Copy/Paste approach HOWEVER your direct copy solution was indeed correct. In my attempt split the copy over two lines, I forgot to add in the continuation underscore ("_") on line 1 and it now works as advertised.
    Thank you,
    Nigel

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem adding column to ListObject, naming it and attempt to Copy or Copy/Paste into

    A Range object does not have a Paste method. You would have had to use PasteSpecial instead.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Adding 8 to row and column cell reference - copy/paste
    By franb123 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-03-2017, 10:27 PM
  2. [SOLVED] Copy filtered column of ListObject to another ListObject
    By snapfade in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2016, 04:00 PM
  3. [SOLVED] copy and paste containing certain words into same naming worksheet
    By watermasa in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 12-27-2013, 02:13 AM
  4. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  5. add sheet naming copy paste
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2010, 02:31 AM
  6. Attempt Copy and Paste
    By Puzzled in Philly in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-01-2010, 06:22 PM
  7. Replies: 1
    Last Post: 01-04-2005, 06:06 PM

Tags for this Thread

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