+ Reply to Thread
Results 1 to 4 of 4

Help modify existing Copy-Paste code

Hybrid View

rizmomin Help modify existing... 09-11-2014, 08:29 AM
Olly Re: Help modify existing... 09-11-2014, 08:52 AM
rizmomin Re: Help modify existing... 09-11-2014, 09:34 AM
Olly Re: Help modify existing... 09-11-2014, 10:03 AM
  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Help modify existing Copy-Paste code

    Hello:

    Please refer to attached file.
    I have 2 sheets "Daily_Receipt" and "Clock-In-Out".
    I will have data coming in "Daily_Receipt" and i am suing vb code below to copy and paste the data
    at the last row of Clock-In_Out sheet.
    I need to check if the same data exist then overwrite the previous data.
    Currently it is adding the data although pasting the same data.

    Please help me modify the code the accomplish this task.
    Basically would need to check date A2 in Daily_Sheet and see if same data exist in Clock-In-Out sheet and if it exist then
    make that the last row and paste the data from Daily_Receipt.

    Let me know if you have any questions.
    Thanks.
    Riz

    Sub CopyAndPasteData()
    
        Dim wSh1 As Worksheet, wSh2 As Worksheet, nEndRw As Long
        Dim xlRng As Range
        Set wSh1 = Sheets("Clock-IN-OUT")
        Set wSh2 = Sheets("Daily_Receipt")
        
        Set xlRng = wSh1.Columns(1).Find(What:=CDate(wSh2.Range("O1").Value), LookIn:=xlFormulas, LookAt:=xlWhole)
        If Not xlRng Is Nothing Then
            If vbNo = MsgBox("Date Exist." & vbLf & "Do you want to copy?", vbYesNo + vbQuestion, "Copy") Then
                Exit Sub
            End If
        End If
        nEndRw = wSh2.Cells(Rows.Count, "A").End(xlUp).Row
        wSh2.Range("A2:D" & nEndRw).Copy wSh1.Cells(Rows.Count, "A").End(xlUp)(2)
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help modify existing Copy-Paste code

    Try:
    Sub foo()
    'code written by Olly @ ExcelForum
    Dim wsSrc As Worksheet, wsTgt As Worksheet
    Dim cSrc As Range, cTgt As Range
    
    Set wsSrc = Sheets("Daily_Receipt")
    Set wsTgt = Sheets("Clock-IN-OUT")
    
    Set cSrc = wsSrc.Range("A2")
    Set cTgt = wsTgt.Columns("A").Find(wsSrc.Range("A2").Value)
    
    If Not cTgt Is Nothing Then Range(cTgt, cTgt.End(xlDown)).EntireRow.Delete
    Range(cSrc.Resize(1, 5), cSrc.End(xlDown)).Cut wsTgt.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Help modify existing Copy-Paste code

    Hi Olly:

    Superb...Thanks a lot

    Riz

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help modify existing Copy-Paste code

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. You can also Add Reputation for posts you found helpful. Thanks.

+ 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. [SOLVED] Modify my Code i can't delete, copy-paste multiple cells also unable to do CTRL + D
    By vengatvj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2013, 01:58 PM
  2. Modify copy & paste code with sorting from A-Z
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-23-2013, 10:49 AM
  3. [SOLVED] Please help me to modify the code copy/paste/transpose
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-30-2013, 09:44 AM
  4. [SOLVED] Modify Existing Mbr Code to Save to Ext.Workbook
    By Miskondukt in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 03-06-2013, 02:36 PM
  5. Code to copy, paste without replacing the existing data
    By share knowledge in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-04-2011, 05:50 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