+ Reply to Thread
Results 1 to 4 of 4

copy and paste data to another workbook vba

Hybrid View

salazarcl.17 copy and paste data to... 03-21-2016, 01:27 AM
spitfireblue Re: copy and paste data to... 03-21-2016, 02:07 AM
salazarcl.17 Re: copy and paste data to... 03-21-2016, 02:17 AM
spitfireblue Re: copy and paste data to... 03-21-2016, 03:00 AM
  1. #1
    Registered User
    Join Date
    03-13-2016
    Location
    peru
    MS-Off Ver
    2013
    Posts
    24

    Question copy and paste data to another workbook vba

    hi, i have this code,is a code for copy and paste in another workbook but i dont know how to select all the data that i will write and then copy and paste in another workbook. please help me with my code

    Private Sub CommandButton1_Click()
    Dim InputFile As Workbook, OutputFile As Workbook
    Dim Inputpath As String, Outputpath As String '
    Dim lastRow As Long, rng As Range
    
    'Dim lastRow As Long
    'Dim rng As Range
    
    
    Sheets("cotizacion").Select
    
    Set rng = ActiveSheet.Cells
    lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    Range("a" & lastRow).Select
    
        
        ActiveCell.Offset(0, 11) = Tex20
        ActiveCell.Offset(0, 12) = Combo10
      ActiveCell.Offset(0, 13) = Combo20
        ActiveCell.Offset(0, 14) = Combo30
         ActiveCell.Offset(0, 15) = Tex12
          ActiveCell.Offset(0, 16) = Tex13
          ActiveCell.Offset(0, 17) = combo40
        ActiveCell.Offset(0, 18) = Tex15
        ActiveCell.Offset(0, 19) = Tex16
        
        Sheets("Origen1").Select
        
        lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    Range("a" & lastRow).Select
    
        
        ActiveCell.Offset(0, 11) = Tex20
        ActiveCell.Offset(0, 12) = Combo10
      ActiveCell.Offset(0, 13) = Combo20
        ActiveCell.Offset(0, 14) = Combo30
         ActiveCell.Offset(0, 15) = Tex12
          ActiveCell.Offset(0, 16) = Tex13
          ActiveCell.Offset(0, 17) = combo40
        ActiveCell.Offset(0, 18) = Tex15
        ActiveCell.Offset(0, 19) = Tex16
        
        
    'Set rng = ActiveSheet.Cells
    'lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    
    '## Open both workbooks first:
    Set InputFile = ActiveWorkbook
    Set OutputFile = Workbooks.Open(ThisWorkbook.Path & "\LibroDestino.xlsm")
    
    'Now, copy what you want from InputFile:
    InputFile.Sheets("Origen1").Range("A2", Range("A2").End(xlToRight)).Select.Copy
    
     'Range("a2", Range("a2").End(xlToRight)).Select
    
    'Now, paste to OutputFile worksheet:
    
    OutputFile.Sheets("destino").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteAll
    'Close InputFile & OutputFile:
    OutputFile.Close True
    
    Range("A2", Range("A2").End(xlToRight)).Select
    
    Selection.ClearContents
    
    
        
         Unload ingresodatos
    ingresodatos.Show
        
     End Sub

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: copy and paste data to another workbook vba

    Hi,

    I think that your problem is here:

    InputFile.Sheets("Origen1").Range("A2", Range("A2").End(xlToRight)).Select.Copy
    Try running your code without the .Select

  3. #3
    Registered User
    Join Date
    03-13-2016
    Location
    peru
    MS-Off Ver
    2013
    Posts
    24

    Re: copy and paste data to another workbook vba

    yeah thats one of my problems but do you know how can i select all the written data and then paste it into another workbook . after try many times i just select a range, but then another problem appears because first i copy in one sheet and after that in another and in the last sheet it select the range of the other sheet and write there and i dont know how to fix that
    
    Private Sub CommandButton1_Click()
    Dim InputFile As Workbook, OutputFile As Workbook
    Dim Inputpath As String, Outputpath As String '
    Dim lastRow As Long, rng As Range
    
    
    
    'Dim lastRow As Long
    'Dim rng As Range
    
    
    
    Sheets("cotizacion").Select
    Set rng = ActiveSheet.Cells
    lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    Range("a" & lastRow).Select
    
        
        ActiveCell.Offset(0, 11) = Tex20
        ActiveCell.Offset(0, 12) = Combo10
      ActiveCell.Offset(0, 13) = Combo20
        ActiveCell.Offset(0, 14) = Combo30
         ActiveCell.Offset(0, 15) = Tex12
          ActiveCell.Offset(0, 16) = Tex13
          ActiveCell.Offset(0, 17) = combo40
        ActiveCell.Offset(0, 18) = Tex15
        ActiveCell.Offset(0, 19) = Tex16
        
        Sheets("Origen1").Select
        
      Set rng = ActiveSheet.Cells
    lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    Range("a" & lastRow).Select
    
        
        'Set rng1 = ActiveSheet.Cells
        'lastRow2 = rng1.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    'Range("a" & lastRow2).Select
    
        
        ActiveCell.Offset(0, 11) = Tex20
        ActiveCell.Offset(0, 12) = Combo10
      ActiveCell.Offset(0, 13) = Combo20
        ActiveCell.Offset(0, 14) = Combo30
         ActiveCell.Offset(0, 15) = Tex12
          ActiveCell.Offset(0, 16) = Tex13
          ActiveCell.Offset(0, 17) = combo40
        ActiveCell.Offset(0, 18) = Tex15
        ActiveCell.Offset(0, 19) = Tex16
        
        
        
        
    
    'Set rng = ActiveSheet.Cells
    'lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1
    
    '## Open both workbooks first:
    Set InputFile = ActiveWorkbook
    Set OutputFile = Workbooks.Open(ThisWorkbook.Path & "\LibroDestino.xlsm")
    
    'Now, copy what you want from InputFile:
    InputFile.Sheets("Origen1").Range("A2:S27").Copy
    
     
    
    'Now, paste to OutputFile worksheet:
    
    OutputFile.Sheets("destino").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteAll
    'Close InputFile & OutputFile:
    OutputFile.Close True
    
    Range("A2:S27").Select
    
    Selection.ClearContents
    
    
        
         Unload ingresodatos
    ingresodatos.Show
        
     End Sub

  4. #4
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: copy and paste data to another workbook vba

    Select your sheet first i.e.

    InputFile.Sheets("Origen1").Select
    Range("A2", Range("A2").End(xlToRight)).Copy

+ 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: 12
    Last Post: 10-28-2015, 11:48 PM
  2. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  3. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  4. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  5. Replies: 6
    Last Post: 01-29-2013, 07:01 AM
  6. Copy/Paste range of data excluding certain rows and copy to another workbook
    By HoerbigAdm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2012, 02:51 PM
  7. Copy data from workbook, create new workbook, paste data to new worbook?
    By mpkavanagh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-16-2011, 06:39 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