+ Reply to Thread
Results 1 to 9 of 9

Error 1004 when VBA paste code to excel

  1. #1
    Registered User
    Join Date
    04-13-2016
    Location
    ck
    MS-Off Ver
    2007
    Posts
    5

    Error 1004 when VBA paste code to excel

    Hello,
    i have fallowing problem:
    create a formula to calculate the latest hour in flexible range (e.g. 14:00-22:30 and 22:00-06:00 the code should give 06:00 or 08:00-12:00 and 09:00-14:00 give 14:00, etc) moreover in rage can be blank cell or other value.
    This part is already done, so i put this formula into vba and here is my issue.
    the code

    Please Login or Register  to view this content.
    unfortunately there is 1004 error

    i divide this code to 3 different cells and here is surprise - no 1004 error
    Please Login or Register  to view this content.
    T - if there is shift through the midnight (22:00-06:00; 21:00-01:00, etc)
    Please Login or Register  to view this content.
    F - shift end before midnight
    Please Login or Register  to view this content.
    the last code give me this error if i put it into formula as a T or as a F

    Any idea to solve?
    Last edited by Test1515; 04-19-2016 at 04:56 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Error 1004 when VBA paste code to excel

    Do you have each of the formulae working on the worksheet? If so, please post the actual formulae and indicate the cell that it goes in.

    Ideally, post a sample workbook with some typical data and your code.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    04-13-2016
    Location
    ck
    MS-Off Ver
    2007
    Posts
    5

    Re: Error 1004 when VBA paste code to excel

    Thank you for answer.
    i don't know why but i cannot add attachment or even picture
    so this my data, please use ctrl+shift+enter and use "record macro"


    in tab1 this formula is correct but vba wont put it into cell
    in tab 2 I divide formula into 3 parts and separately work all, error comes out when I add 3th part instead of "F"


    shift1 shift2 time formula
    08:00-16:00 22:00-05:30 08:00-05:30 =TEXT(IF(MAX(IF(MID(A3:B3,6,1)="-",IF(MID(A3:B3,7,5)*1<MID(A3:B3,1,5)*1,MID(A3:B3,7,5)*1,"0"),"0"))=0,MAX(IF(MID(A3:B3,6,1)="-",MID(A3:B3,7,5)*1,"0")),MAX(IF(MID(A3:B3,6,1)="-",IF(MID(A3:B3,7,5)*1<MID(A3:B3,1,5)*1,MID(A3:B3,7,5)*1,"0"),"0"))),"HH:MM")
    08:00-16:00 08:00-22:00 08:00-22:00
    08:00-16:00 (blank) 08:00-16:00
    tab2
    08:00-16:00 22:00-05:30 F =TEXT(IF(MAX(IF(MID(A8:B8,6,1)="-",IF(MID(A8:B8,7,5)*1<MID(A8:B8,1,5)*1,MID(A8:B8,7,5)*1,"0"),"0"))=0,"T","F"),"HH:MM")
    08:00-16:00 22:00-05:30 16:30 =TEXT(MAX(IF(MID(A8:B8,6,1)="-",MID(A8:B8,7,5)*1,"0")),"HH:MM")
    08:00-16:00 22:00-05:30 05:30 =TEXT(MAX(IF(MID(A10:B10,6,1)="-",IF(MID(A10:B10,7,5)*1<MID(A10:B10,1,5)*1,MID(A10:B10,7,5)*1,"0"),"0")),"HH:MM")

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: Error 1004 when VBA paste code to excel

    I've tried it like this:

    Please Login or Register  to view this content.
    But still no joy. Note that "0" is a text string, as opposed to just 0 which is the numeric value zero. That said, it still doesn't work I will seek input from others.

  5. #5
    Registered User
    Join Date
    04-13-2016
    Location
    ck
    MS-Off Ver
    2007
    Posts
    5

    Re: Error 1004 when VBA paste code to excel

    Quote Originally Posted by TMS View Post
    Note that "0" is a text string...
    This is why i put *1 after fragment of my string

    The main question is why vba not allow in first IF function "if false".

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Error 1004 when VBA paste code to excel

    See how this goes
    Uses sendkeys so its not ideal but using vba to set the formula array appears to have some limitations.
    the macro 1 is just your formula being passed to shg's macro.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-13-2016
    Location
    ck
    MS-Off Ver
    2007
    Posts
    5

    Re: Error 1004 when VBA paste code to excel

    Thank you for this solution but is not "user friendly" i decide to put somewhere 1 cell with activated array formula and using Cells.Replace to change range.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Error 1004 when VBA paste code to excel

    It's just that your formula is too long. You can do something like this:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-13-2016
    Location
    ck
    MS-Off Ver
    2007
    Posts
    5

    Re: Error 1004 when VBA paste code to excel

    rorya - you won...

    ...my happiness! - is always something

    Thanks
    [Solved]

+ 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. When Activesheet.paste, Run-Time error '1004': Paste method of work sheet class failed.
    By devaraj2020 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2015, 01:59 AM
  2. Excel VBA copy paste 1004 error
    By salonee in forum Excel General
    Replies: 2
    Last Post: 12-19-2014, 10:53 AM
  3. [SOLVED] runtime error 1004 paste method of worksheet class failed Excel 2003
    By chris_1860 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-10-2014, 05:53 AM
  4. Runtime error '1004': Paste special method of range class error.
    By Daryl Zer0 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-05-2014, 01:44 AM
  5. Run time error 1004 on picture copy and paste - excel 2010
    By talon10 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2014, 08:14 PM
  6. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  7. Replies: 0
    Last Post: 09-12-2007, 02:40 AM

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