Consolidating columns when you need to keep one value over another

sgrad

New Member
Joined
Jun 30, 2015
Messages
1
I need to consolidate 3 columns of phone numbers into 1 column, but I need to be able to prioritize the data in one column over another. For example if row 1 has a number in all 3 columns I need the consolidation to know that the information in Column D is kept over the information in columns C and B. However for row 2 where there is no given information in Column D the consolidation needs to keep the information for Column C.

So some rows have data in all 3 columns, some have it only 1 or 2, some have it in none. But in the consolidation column D data needs to be kept over column C and column B data, column C data needs to be kept over column B data, and if there is no data in columns D or C than column B data is kept.

How do I make this happen?
 
See if this works for you
Code:
Sub cons()
Dim sh As Worksheet, lr As Long
Set sh = Sheets(1)
lr = sh.Cells(Rows.Count, 2).End(xlUp).Row
    For i = 2 To lr
        With sh
            If i = 2 And .Cells(i, 3) <> "" Then
                .Cells(i, 2) = .Cells(i, 3).Value
            ElseIf i > 2 Then
                If .Cells(i, 4) <> "" Then
                    .Cells(i, 2) = .Cells(i, 4).Value
                ElseIf .Cells(i, 4) = "" And Cells(i, 3) <> "" Then
                    .Cells(i, 2) = .Cells(i, 3).Value
                End If
            End If
        End With
    Next
    sh.Range("C2, C3:D" & lr).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,906
Messages
6,193,596
Members
453,810
Latest member
Gks77117

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