Add unique values in one Col to bottom of another

FredMFoley

Board Regular
Joined
Mar 18, 2002
Messages
58
Can anyone please help with VBA code to add the values which are unique to Col B, to the end of Col A. ie I would like Col A to have a and c added to the end, without changing the order of the existing values.

Col A
q
w
e
r

Col B
a
c
w
e
This message was edited by FredMFoley on 2002-05-06 17:55
This message was edited by FredMFoley on 2002-05-06 18:06
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
This Macro assumes the sheet your using is Sheet2 So you may want to change that aspect of the macro

Sub AddColB2ColA()

'Find End of ColA
Do
BotOfColA = BotOfColA + 1
Loop Until Len(Trim(Worksheets("Sheet2").Cells(BotOfColA, 1).Value)) = 0


Do
RowCnt = RowCnt + 1


'Get a search value from col B
SrchVal = Worksheets("Sheet2").Cells(RowCnt, 2).Value

'See if can find search value in colA
Set Fnd = Worksheets("Sheet2").Range("A:A").Find(SrchVal, LookIn:=xlValues)
If Fnd Is Nothing Then ' add search value to col A
Worksheets("Sheet2").Cells(BotOfColA, 1).Value = SrchVal
BotOfColA = BotOfColA + 1
End If
Loop Until Len(Trim(Worksheets("Sheet2").Cells(RowCnt, 2).Value)) = 0

End Sub
This message was edited by Nimrod on 2002-05-06 19:07
 
Upvote 0
This example assumes that the data is on sheet1 and that there are no blanks in the data. (it may work with blanks, I just haven't test it with them :) )<pre>
Public Sub main()

Dim oCell As Range
Dim oRange As Range

With Sheets("Sheet1")
Set oRange = Range(.Range("B1"), .UsedRange.Columns("B"))


For Each oCell In oRange
If .UsedRange.Columns("A").Find(what:=oCell.Value, lookat:=xlWhole) Is Nothing Then
.Range("A65536").End(xlUp).Offset(1, 0).Value = oCell.Value
End If
Next
End With

End Sub</pre>

HTH


_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-05-06 19:16
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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