+ Reply to Thread
Results 1 to 5 of 5

PasteSpecial error text to number

  1. #1
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    PasteSpecial error text to number

    Hi,

    Stuck again, sample file should show my problem.

    Open txt file and sample file to Sheet1, select data in txt file and use Insert button on Sheet1 to paste data.

    Data copies as I require but formatting on columns F:H has errors? If I click error next to cell and convert to number it formats right.

    How do I change code to make this work. I have tried time and time again with PasteSpecial and even looked in to calling a macro to delimit but no success.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: PasteSpecial error text to number

    Can try this, red part maybe can be shorter but it works.

    Please Login or Register  to view this content.
    Kind regards

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: PasteSpecial error text to number

    Add following 2 lines in bold just before End Sub.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Re: PasteSpecial error text to number

    Thanks both for your replies

    #3 seems to be the easiest way to adapt my code and it works so thanks again. Just needed to add a formula to a particular cell so stop it being overwritten.

    LeoTaxi I see I was probably not thinking of using the With command so thanks for the education, tried everything but I think lol

    Will let you know later if it definitely works once I've tried it at work as that's where the problem always occurs


  5. #5
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Re: PasteSpecial error text to number

    So... just do update.

    Code I was using before this post was

    Please Login or Register  to view this content.
    I am pulling data from a work document and not sure of coding, when I ctrl C & ctrl V to notepad and then back to a blank excel sheet then copy from that sheet to my working sheet the data pastes as needed hence why my macro starts the way it does.

    I am pasting in to blank sheet (Sheet1) to Range A1, when it works all works as it should. Clears cells in Sheet1 and kills Notepad.

    Adding the two lines suggested in post #3 fixed the format issue
    Please Login or Register  to view this content.
    Still randomly getting an error when running the macro

    Run-time error '1004':
    Paste method of worksheet class failed

    Please Login or Register  to view this content.
    Debug shows code in red as the error

    Not sure how I would put the suggestion in post #2 in to my macro as a whole, and not sure why I am getting this error

+ 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] PasteSpecial x1PasteValues error
    By aaaaa34 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2020, 08:56 AM
  2. PasteSpecial VBA Error
    By radek225 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2017, 08:11 AM
  3. [SOLVED] PasteSpecial Run-Time Error 1004
    By lilsum1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2015, 04:59 PM
  4. Excel 2007 PasteSpecial Error
    By CMSS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2010, 10:46 AM
  5. Run-time error '1004' PasteSpecial
    By STarloff in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-27-2010, 10:14 AM
  6. Runtime Error 1004 when trying to PasteSpecial
    By Phil Davis in forum Excel General
    Replies: 2
    Last Post: 02-16-2006, 06:10 PM
  7. [SOLVED] PasteSpecial error handling
    By JakeyC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2005, 03:05 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