Locate duplicate values in a column, copy/paste adjacent value

davidanaya11579

New Member
Joined
Dec 26, 2017
Messages
11
I'm working on a report with thousands of entries. For some reason, the report only returns data in column C the first time a value appears in column B, for all subsequent entries of that value(B), Column C remains empty. I need to locate all duplicate values in column B, and copy the value of Column C into all subsequent entries.

Example of Raw Report:
[TABLE="width: 311"]
<tbody>[TR]
[TD]LoadNum[/TD]
[TD]Prim Load#[/TD]
[TD]SSLine B/L[/TD]
[/TR]
[TR]
[TD="align: right"]237098864[/TD]
[TD="align: right"]237098864[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]238921496[/TD]
[TD="align: right"]238921496[/TD]
[TD]238921496WAW[/TD]
[/TR]
[TR]
[TD="align: right"]240817258[/TD]
[TD="align: right"]240817258[/TD]
[TD]240817258NGB[/TD]
[/TR]
[TR]
[TD="align: right"]242967262[/TD]
[TD="align: right"]242967262[/TD]
[TD]MSCUJR543586[/TD]
[/TR]
[TR]
[TD="align: right"]245434172[/TD]
[TD="align: right"]242967262[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]242984183[/TD]
[TD="align: right"]242984183[/TD]
[TD]HLCUCHI171002103[/TD]
[/TR]
[TR]
[TD="align: right"]242988571[/TD]
[TD="align: right"]242988571[/TD]
[TD]HLCUCHI171034120[/TD]
[/TR]
[TR]
[TD="align: right"]242989105[/TD]
[TD="align: right"]242988571[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]242989108[/TD]
[TD="align: right"]242988571[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD] [/TD]
[/TR]
</tbody><colgroup><col span="2"><col></colgroup>[/TABLE]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If your data in column B is always sorted so that the same values are always together as in the sample you posted, then this macro should do what you want. Shouldn't the first value in column B (237098864) have data to the right in column C since it is the first time it appears? If you place a value in C2, the macro should work.
Code:
Sub CopyVal()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    For Each rng In Range("C2:C" & LastRow)
        If rng = "" Then
            rng = rng.Offset(-1, 0)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,778
Members
453,371
Latest member
HMX180

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