Results 1 to 16 of 16

Copy successive columns to a closed workbook

Threaded View

RedWing Copy successive columns to a... 09-07-2011, 04:27 AM
romperstomper Re: Copy successive columns... 09-07-2011, 06:04 AM
RedWing Re: Copy successive columns... 09-07-2011, 06:13 AM
RedWing Re: Copy successive columns... 09-07-2011, 06:37 AM
romperstomper Re: Copy successive columns... 09-07-2011, 06:40 AM
RedWing Re: Copy successive columns... 09-07-2011, 10:17 AM
RedWing Re: Copy successive columns... 09-07-2011, 10:18 AM
romperstomper Re: Copy successive columns... 09-07-2011, 10:25 AM
RedWing Re: Copy successive columns... 09-07-2011, 10:30 AM
romperstomper Re: Copy successive columns... 09-07-2011, 10:36 AM
RedWing Re: Copy successive columns... 09-07-2011, 10:40 AM
RedWing Re: Copy successive columns... 09-08-2011, 07:11 AM
romperstomper Re: Copy successive columns... 09-08-2011, 08:15 AM
RedWing Re: Copy successive columns... 09-08-2011, 08:19 AM
romperstomper Re: Copy successive columns... 09-08-2011, 08:23 AM
RedWing Re: Copy successive columns... 09-08-2011, 04:38 PM
  1. #1
    Registered User
    Join Date
    09-06-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    40

    Copy successive columns to a closed workbook

    Hi,

    I have columns of data in a master workbook. I want to be able to copy a single column to a separate closed workbook using a macro button. E.g. If the closed workbook is empty to start with. Then clicking the button once will copy the data to Column 1 in the closed worksheet selected, then clicking it again will copy the data to Column 2... and the next time to Column 3 etc, so that each iteration of data is saved in columns.

    I haven't had much like finding a code for this and I am rather new to VBA, I came across this code which currently copies cells from one workbook to a closed one, and I can modfy this to include the column range I'm interested in, but I don't know how to make it so that each time the code is run, it copies to the next subsequent column, instead of overwriting the same column again and again.

    Option Explicit
    
    Sub copyDataToClosedWorkbook()
        Dim wbTo   As Workbook
        Dim wbFrom As Workbook
    
        Set wbFrom = ThisWorkbook
        ' prevent the user from seeing the workbook being opened
        Application.ScreenUpdating = False
        'change foldername
        Set wbTo = Workbooks.Open("C:\FolderName\Test.xls", _
                                  False, True)
        wbTo.csheet1.Cells(10, 4).Value = wbFrom.Sheet1.Cells(1, 3).Value
        wbTo.Close True    'save & close
        Application.ScreenUpdating = True
        Set wbTo = Nothing
        Set wbFrom = Nothing
    End Sub
    Thanks a lot for your help!
    Last edited by RedWing; 09-07-2011 at 10:41 AM.

Thread Information

Users Browsing this Thread

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

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