+ Reply to Thread
Results 1 to 7 of 7

Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple selections

Hybrid View

Sleever Excel VBA 2010 - Copy to WB,... 09-07-2014, 11:31 AM
HaHoBe Re: Excel VBA 2010 - Copy to... 09-07-2014, 11:50 AM
Sleever Re: Excel VBA 2010 - Copy to... 09-07-2014, 01:52 PM
Sleever Re: Excel VBA 2010 - Copy to... 09-07-2014, 12:02 PM
Norie Re: Excel VBA 2010 - Copy to... 09-07-2014, 12:33 PM
Sleever Re: Excel VBA 2010 - Copy to... 09-07-2014, 01:57 PM
HaHoBe Re: Excel VBA 2010 - Copy to... 09-07-2014, 02:26 PM
  1. #1
    Registered User
    Join Date
    09-07-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    5

    Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple selections

    Dear all,

    I have an issue in my Code.
    Sometimes it runs without issues, and sometimes not. I have not found the system.

    I want to copy a named area in a sheet in current wb (XLSM) to a new workbook. As default, new wb's are xlsx.
    I have read somewhere, that this error can occur, if the new wb is xls. But that is not the case.

    In the worksheet there are som hidden columns, but these are not part if the named area.

    When an issue occurs, it is the same place. Please see the red line below.


    Sub MailAnalysisSub()
    
    Application.ScreenUpdating = False
    
    Dim TempWorkbook As Workbook
    Dim Tempsht As Worksheet
    
    '----------
    'Create new Workbook
    Set TempWorkbook = Workbooks.Add
    FolderPath = Application.ThisWorkbook.Path & "\14.ShipReport_Controller" & "\14.ShipReport_SentReportingPackages\"
    Application.DisplayAlerts = False
    
    TempWorkbook.Activate
    Set Tempsht = Worksheets.Add
    Tempsht1 = ActiveSheet.Name
    ActiveSheet.Name = "Tempsht1"
    
    '------------
    ThisWorkbook.Worksheets("Input_Risk").Activate
    ThisWorkbook.Worksheets("Input_Risk").Unprotect
    Range("PrintArea_NotPaymentRisk").Select
    
    Selection.Copy
    
    TempWorkbook.Activate
    Sheets("Tempsht1").Activate
    Cells(1, 1).Activate
    
    Selection.PasteSpecial Paste:=xlPasteValues
    Selection.PasteSpecial Paste:=xlPasteFormats
    Selection.Name = "PrintArea_NotPaymentRisk"
    
    Application.CutCopyMode = False
    
    
    
    ...more code.......
    I hope you can shed som light over this issue - what am I doing wrong, and most exciting, why is this not a consequence error. Sometimes it works, sometimes not.

    wbr
    Benjamin
    Last edited by Sleever; 09-07-2014 at 01:50 PM. Reason: Adding [CODE] as requested

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Hi, Sleever,

    please have a read at Forum Rule #3 and add code-tags to your procedure as explained there.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    09-07-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    5

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Hi Holger,

    I appologize for my novice answer. I have now read and understood #3 - and have corrected the mistake.
    Thanks for letting me know. I was defensive, because I have seen before on other forums how some people find it more interesting to put rules on others, than actually doing what the forum is all about.


    Hope you accept,

    wbr
    Ben

  4. #4
    Registered User
    Join Date
    09-07-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    5

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Hi Holger,

    Dont see the issue wrt. #3 - very easy to replicate code.
    Easy so select code, and to paste directly into module for testing - if wanted.

    I respect "dresscode", but this seems a little off...


    - Sleever

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

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Even easier to add code tags which make the code easier to read and to copy/paste.

    Anyway, does this work?

    
    Range("PrintArea_NotPaymentRisk").Copy 
    
    With Tempsht.Cells(1,1)
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteFormats
    End With
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    09-07-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    5

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Hi Norie,

    yes - you are right. I have appologized to Holger.
    I have tried your code. I get error her;

    Sub MailAnalysisSub()
    
    '---------------------------------------
    'Mail the analysis to the end intepreter
    'Area=PrintArea_PaymentRisk
    '---------------------------------------
    
    Application.ScreenUpdating = False
    
    Dim TempWorkbook As Workbook
    Dim Tempsht As Worksheet
    
    RightHereRightNow = ActiveCell.Address
    RightHereRightNow_Sheet = ActiveSheet.Name
    
    '----------
    'Create new Workbook
    Set TempWorkbook = Workbooks.Add
    FolderPath = Application.ThisWorkbook.Path & "\14.ShipReport_Controller" & "\14.ShipReport_SentReportingPackages\"
    Application.DisplayAlerts = False
    
    TempWorkbook.Activate
    Set Tempsht = Worksheets.Add
    Tempsht1 = ActiveSheet.Name
    ActiveSheet.Name = "Tempsht1"
    
    '------------
    ThisWorkbook.Worksheets("Input_Risk").Activate
    ThisWorkbook.Worksheets("Input_Risk").Unprotect
    
    Range("PrintArea_NotPaymentRisk").Copy
    
    With Tempsht.Cells(1, 1)
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteFormats
    End With
    
    'Range("PrintArea_NotPaymentRisk").Select
    '
    'Selection.Copy
    '
    'TempWorkbook.Activate
    'Sheets("Tempsht1").Activate
    'Cells(1, 1).Activate
    '
    'Selection.PasteSpecial Paste:=xlPasteValues
    'Selection.PasteSpecial Paste:=xlPasteFormats
    Excel error: Run-time errot '1004':
    PasteSpecial method of Range class failed.


    wbr
    Ben
    Last edited by Sleever; 09-07-2014 at 02:11 PM. Reason: Updating Excel erro

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Excel VBA 2010 - Copy to WB, RTE 1004 - That command cannot be used on multiple select

    Hi, Ben,

    you should try and work with objects throughout (I know: easy to tell and hard to do).

    Maybe try
    Range("PrintArea_NotPaymentRisk").Copy Tempsht.Cells(1, 1)
    
    With Tempsht.Cells(1, 1).CurrentRegion
      .Value = .Value
      :Name = "PrintArea_NotPaymentRisk"
    End With
    instead of
    Range("PrintArea_NotPaymentRisk").Copy
    
    With Tempsht.Cells(1, 1)
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteFormats
    End With
    Ciao,
    Holger

+ 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. Replies: 4
    Last Post: 10-21-2013, 02:55 PM
  2. Copy and paste for multiple selections
    By amartino44 in forum Excel General
    Replies: 3
    Last Post: 07-12-2013, 02:34 PM
  3. Replies: 3
    Last Post: 05-16-2013, 06:08 AM
  4. Copy multiple selections in excel 2003
    By John Musbach in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2009, 09:08 PM
  5. [SOLVED] I cannot do the oopy paste command in multiple selections in the .
    By Penny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2005, 12: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