ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sync Code (https://www.excelbanter.com/excel-programming/295109-sync-code.html)

Todd huttenstine

Sync Code
 
Hey guys

I have 2 ranges. A:A and B:B. What is the code that will
go through range A:A and if it finds a value that is NOT
in range B:B, it will add it. If a value in range A:A is
found, then do nothing.


Todd

Bob Phillips[_6_]

Sync Code
 
Hi Todd,

One way

Sub Sync()
Dim i As Long
Dim cLastB As Long
Dim oCell As Range

cLastB = Cells(Rows.Count, "B").End(xlUp).Row

On Error Resume Next
For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
Set oCell = Columns(2).Find(Cells(i, "A").Value)
If oCell Is Nothing Then
cLastB = cLastB + 1
Cells(cLastB, "B").Value = Cells(i, "A").Value
End If
Set oCell = Nothing
Next i

On Error GoTo 0

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
Hey guys

I have 2 ranges. A:A and B:B. What is the code that will
go through range A:A and if it finds a value that is NOT
in range B:B, it will add it. If a value in range A:A is
found, then do nothing.


Todd




Frank Kabel

Sync Code
 
Hi Todd
dou you need a VBA solution or would a worksheet formula also work for
you?. You may try
=SUMPRODUCT(--(COUNTIF(B1:B1000,A1:A1000)=0),A1:A1000)

--
Regards
Frank Kabel
Frankfurt, Germany


Todd Huttenstine wrote:
Hey guys

I have 2 ranges. A:A and B:B. What is the code that will
go through range A:A and if it finds a value that is NOT
in range B:B, it will add it. If a value in range A:A is
found, then do nothing.


Todd




All times are GMT +1. The time now is 12:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com