Only copy cells value based on UID

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I have this code which copies over values from the active worksheet to a sheet called "Actions" under the next available line if the value in "G" is equal to "A"

Can anyone help me please, I want to also only copy over only unique lines. (UID)

"B & E" together would be the UID but I am struggling to modify the code to include the UID

This is my exiting code

Code:
Sub Copy()
    Dim sh1 As Worksheet
    Dim sh2 As Worksheet
    Dim LR1 As Long
    Dim LR2 As Long
    Dim i As Long
    Dim j As Long
    Dim uid As String
    
    Application.ScreenUpdating = False
    
    Set sh1 = ActiveSheet 'original sheet
    Set sh2 = Sheets("Actions") 'destination sheet
    
    LR1 = sh1.Cells(Rows.Count, "B").End(xlUp).Row
    LR2 = sh2.Cells(Rows.Count, "B").End(xlUp).Row
    
    j = LR2
    For i = LR1 To 2 Step -1
        If sh1.Cells(i, 7) = "A" Then
            j = j + 1
       
            sh2.Range("B" & j).Value = sh1.Range("A" & i).Value
            sh2.Range("C" & j).Value = sh1.Range("B" & i).Value
            sh2.Range("D" & j).Value = sh1.Range("C" & i).Value
            sh2.Range("E" & j).Value = sh1.Range("E" & i).Value
            sh2.Range("F" & j).Value = sh1.Range("F" & i).Value
            sh2.Range("G" & j).Value = sh1.Range("H" & i).Value
            sh2.Range("I" & j).Value = sh1.Range("I" & i).Value
            sh2.Range("I" & j).Value = Format(Date, "dd mmm yy")
        End If
    Next
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Can you post a screen shot of what your data looks like? Section B at this link has instructions on how to post a screen shot: https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html Alternately, you could upload a copy of your file to a free site such as www.box.com. or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top