+ Reply to Thread
Results 1 to 6 of 6

Thread: Copy and Paste non-contiguo data to another sheet

  1. #1
    Registered User
    Join Date
    10-24-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Copy and Paste non-contiguo data to another sheet

    I need some help on how to make a storage button.

    So basically, theres a sheet in the spreadsheet called "Invoice" and it has all the details like Costs, Customer ID, Product ID"

    I need this information so when you press the button it gets automatically entered into a "invoice database" page so in a row it has like Customer ID, Product ID, Costs and it gets put under the columns it falls under.

    You could do this with a Macro, but the tricky thing is making it so when you press the button again it goes onto the next row. Otherwise it will just keep over-writing the first row.

    So making it when you press the button it, writes to the row. Then if you press again, it writes the row below it.

    Anyone know how to do that? If you wish to speak on MSN just pm me

    Thanks!
    Last edited by PowerZ; 10-25-2010 at 10:16 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Help on storing cells in another sheet- Copy and Paste non-contiguo to another sh

    Check out this code, change the range to meet your requirements
    Sub CopyCode()
    
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim s As Range, z As Range, c As Range
        Dim x As Integer, y As Integer
    
        Set ws1 = Worksheets("Sheet1")    'determins sheet to copy from
        Set ws2 = Worksheets("Sheet2")    'determons sheet to paste to
        Set s = ws1.Range("A1,B3,C4,D4")    'determins range to copy
    
        x = 0    'first cell to paste to is "ws2.Range("A65536").End(xlUp).Offset(1, 0)" then changes as the loop progresses
        y = 1
    
        For Each c In s.Cells
    
            Set z = ws2.Range("A65536").End(xlUp).Offset(y, x)    'finds 1st empty cell after last filled cell
    
            c.Copy Destination:=z
    
            x = x + 1
            y = 0
    
        Next c
    
    End Sub

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Help on storing cells in another sheet- Copy and Paste non-contiguo to another sh

    Here is a very simple example, but it should work in your case

    Click the button, the ranges will be copied to the next sheet
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-24-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Help on storing cells in another sheet- Copy and Paste non-contiguo to another sh

    @Davesexcel You are amazing. One last thing, How can I change where the first line is put in on Sheet 2.

    So instead of the row starting at Column A, If i wanted it too start at Column D?

    Thank's again for replying so fast!

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Help on storing cells in another sheet- Copy and Paste non-contiguo to another sh

    Change the A65536 to a D65536

  6. #6
    Registered User
    Join Date
    10-24-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Help on storing cells in another sheet- Copy and Paste non-contiguo to another sh

    Thank's dave for all the help!

    Much appreciated!

    ~JSN

+ Reply to Thread

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.2.0