View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
saman110 via OfficeKB.com saman110 via OfficeKB.com is offline
external usenet poster
 
Posts: 80
Default find closest match and copy to sheet1

Joel,

Thank you for responding,

I get syntax error becase this line is in red: closest = rng1)

any idea?
thx.


Joel wrote:
Sub CopyIDData()
Dim rng As Range
Dim rng1 As Range
Dim cell As Range
Dim res As Variant

With Worksheets("sheet1")
Set rng = .Range(.Range("A1"), .Range("A1").End(xlDown))
End With
With Worksheets("Sheet2")
Set rng1 = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With

For Each cell In rng
first = true
for each cell1 in Rng1
if first = true then
closest = rng1
first = false
else
if abs(rng - rng1) < abs(rng - closest) then
closest = rng1)
end if
next cell1
cell.Offset(0, 1) = closest
Next
End Sub

Hello,

[quoted text clipped - 55 lines]

Thank you.


--
Message posted via http://www.officekb.com