+ Reply to Thread
Results 1 to 19 of 19

Code to Copy & Paste/ Clear Range

  1. #1
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Code to Copy & Paste/ Clear Range

    Hi,

    In the Invoice Data2 sheet there are cells highlighted yellow that I would like to have posted to the Database Table A:K starting in row 17 like in my example please. Can one button post this data and clear for new or should there be 2 buttons?

    Thank you very much for your help

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: Code to Copy & Paste/ Clear Range

    It would be best to have 2 buttons; one that Copies the data to the Database; and the other to Clear for new items.

  3. #3
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Okay great thanks queuesef. Are you able to derive the codes?

  4. #4
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Code to Copy & Paste/ Clear Range

    In my opinion, both ranges are the same, so all you need is one button.
    New data will be written when you use Button 'Add'.
    Assign my code to the 'Add' button.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Best Regards,
    Maras.

  5. #5
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Thanks maras_mak I implemented your code.

    The REF column is not matching the numbers for data and would it be possible to not have the blank rows? The 6, 7, 8, 9 don't have data but are copied.

    How to clear the cells for next time?

  6. #6
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Code to Copy & Paste/ Clear Range

    Bart60, cells are automatically cleaned before entering new values.
    Correct my code to this.
    Please Login or Register  to view this content.
    Last edited by maras_mak; 08-23-2019 at 04:35 PM.

  7. #7
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    That works better thanks. I don't understand how the yellow cells get cleared when I want to enter another invoice.

    Can you please explain?

  8. #8
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Maras,

    I am sorry for not being clear. I intended for the database to grow with new invoices as they are added and not replaced.

    Can this code post the data to the next available empty row instead of replacing?

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    Quote Originally Posted by Bart60 View Post
    Can one button post this data and clear for new or should there be 2 buttons?
    One button is enough so according to your attachment a starter demonstration
    to paste to the Invoice Data2 worksheet module :

    PHP Code: 
    Sub Demo1()
       
    Dim R&
           
    = [H3:K13].Find("*", , xlValues, , xlByRowsxlPrevious).Row 3
        
    If R Then
            With 
    [A16].ListObject.Range.Columns(1).Find("*", , , , , xlPrevious)(2)
                .
    Resize(R6).Value = [A4:F4].Value2
                
    .Offset(, 6).Resize(R5).Value2 = [G4:K4].Resize(R).Value2
            End With
                 
    [A4:F4,H4:K13].ClearContents
        End 
    If
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-23-2019 at 09:49 PM. Reason: optimization …

  10. #10
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Code to Copy & Paste/ Clear Range

    Bart60, now everything is clear to me.
    Look at the attachment.
    Attached Files Attached Files

  11. #11
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    @Marc L

    I tried your code but I have requests please. I did some adjustments of the sheet and there are also formulas that I would like to stay so I changed the Clear Contents part of the code.

    I have an issue now if I only enter one line item (service or material) it doesn't post the data or clear the area. Also if I have more that one item let's say 4 only 3 line items are posted.

    If you have the time can you check please?

    Thank you
    Last edited by Bart60; 08-25-2019 at 06:14 AM.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Your bad : delete Module1 then this time well read & apply the dark red direction just before the code !
    And amend the ClearContents codeline for the ranges to clear …

  13. #13
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Code to Copy & Paste/ Clear Range

    Bart60, if you want use my code adapted to your new data layout.
    Please Login or Register  to view this content.

  14. #14
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Thank you Maras for the edited code to fit my new layout. I opted to use the code from Marc L it seems less complicated. I hope you can understand my choice.

    Please Login or Register  to view this content.
    Last edited by Bart60; 08-26-2019 at 06:10 AM.

  15. #15
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Code to Copy & Paste/ Clear Range

    You're welcome. The choice is yours.

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation

    Quote Originally Posted by Bart60 View Post
    I opted to use the code from Marc L
    Bad mod in the first Find codeline as the search range must contain the header so it's I1:I11 then - 1 is the good value at end …

  17. #17
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Revisit results sometimes the Cust ID is posting as a date not sure why. It happens with either code.

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    Format the source cell as text and if the issue remains attach a workbook accordingly …

  19. #19
    Banned User!
    Join Date
    08-14-2019
    Location
    UK
    MS-Off Ver
    2010
    Posts
    72

    Re: Code to Copy & Paste/ Clear Range

    Changing the "2" to a "1" seems to work thanks Marc L

+ 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. VB Code to create range to copy and paste
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2018, 08:18 AM
  2. Copy, paste, and clear contents (i.e move) a range depending on combobox selection
    By ANDLU89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2018, 03:43 AM
  3. VBA Code to Copy Dynamic Named Range in WS to another WS then Clear
    By em1335 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2016, 06:19 PM
  4. [SOLVED] Copy/paste data using checkbox-clear when unchckd & multiple selections paste in next cell
    By Staceymcw in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-02-2015, 12:09 AM
  5. [SOLVED] Userform button action - clear,copy paste and print crashes. Please help with code
    By intex in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-05-2014, 12:16 PM
  6. Replies: 18
    Last Post: 02-10-2013, 05:32 PM
  7. CheckBox Code to copy & paste range
    By Casey in forum Excel General
    Replies: 0
    Last Post: 10-13-2005, 12:32 PM

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