Matching two columns cell for cell

Moonbeam111

Board Regular
Joined
Sep 24, 2018
Messages
73
Office Version
  1. 365
  2. 2010
I basically am trying to have column A match Column B exactly. All values in both columns are alphabetically organized but Column B has some extra values I don't want.

aA
bB
cM
dC
eD
fP
gE


In this example, it would delete the cells M and P in column 2 so that both columns have the same values.

I have this code but it doesn't work quite right when I test it.

Sub Button2_Click()
For Each cell In Range("B2:B478")
If cell = cell.Offset(, -1) Then
Else
cell.delete
End If
Next cell
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this:

VBA Code:
Sub comparecolumns()
  Dim cell As Range, f As Range
  
  For Each cell In Range("A2", Range("A" & Rows.Count).End(3))
    If LCase(cell.Value) <> LCase(cell.Offset(, 1).Value) Then
      cell.Offset(, 1).ClearContents
      Set f = Range("B" & cell.Row, Range("B" & Rows.Count).End(3)).Find(cell.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then cell.Offset(, 1).Value = f.Value
    End If
  Next
End Sub
 
Upvote 0
Solution
Another one.
Code:
Sub Who_Knows()
Dim datArr, i As Long
datArr = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value
ReDim Preserve datArr(1 To UBound(datArr), 1 To 2)
    For i = LBound(datArr) To UBound(datArr)
        datArr(i, 2) = UCase(datArr(i, 1))
    Next i
Columns(2).ClearContents
Cells(1, 2).Resize(UBound(datArr, 1)).Value = Application.Index(datArr, , 2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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