![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Location: Tasmania
Posts: 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 ] |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
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 ] |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
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
HTH _________________ [b] Mark O'Brien [ This Message was edited by: Mark O'Brien on 2002-05-06 19:16 ] |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Tasmania
Posts: 58
|
Thank you both very much.
(Mark's example seems happy with spaces in either column.) |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|