[B][color=Royalblue]Sub[/color][/B] a1075525f()
[i][color=seagreen]'https://www.mrexcel.com/forum/excel-questions/1075525-match-positive-numeric-value-negative.html[/color][/i]
[B][color=Royalblue]Dim[/color][/B] i [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Long[/color][/B], z [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Long[/color][/B], ch [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Long[/color][/B], f [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Long[/color][/B]
[B][color=Royalblue]Dim[/color][/B] rng [B][color=Royalblue]As[/color][/B] Range
[B][color=Royalblue]Dim[/color][/B] m [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]String[/color][/B], cv [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]String[/color][/B], cn [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]String[/color][/B]
[B][color=Royalblue]Dim[/color][/B] va [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Variant[/color][/B], vb [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Variant[/color][/B], vc [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Variant[/color][/B], vx [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Variant[/color][/B]
[B][color=Royalblue]Dim[/color][/B] d [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Object[/color][/B], da [B][color=Royalblue]As[/color][/B] [B][color=Royalblue]Object[/color][/B]
Application.ScreenUpdating = [B][color=Royalblue]False[/color][/B]
cv = [color=brown]"A"[/color] [i][color=seagreen]'vendor column[/color][/i]
cn = [color=brown]"B"[/color] [i][color=seagreen]'number column[/color][/i]
ch = [color=crimson]6[/color] [i][color=seagreen]'the first column of the helper column, so if the helper column is X:Z then ch = 24[/color][/i]
rr = Range(cv & Rows.count).[B][color=Royalblue]End[/color][/B](xlUp).row
Range(Cells([color=crimson]1[/color], ch + [color=crimson]1[/color]), Cells(rr, ch + [color=crimson]1[/color])).Value = Range(Cells([color=crimson]1[/color], cv), Cells(rr, cv)).Value
Range(Cells([color=crimson]1[/color], ch + [color=crimson]2[/color]), Cells(rr, ch + [color=crimson]2[/color])).Value = Range(Cells([color=crimson]1[/color], cn), Cells(rr, cn)).Value
Cells([color=crimson]1[/color], ch).Value = [color=crimson]1[/color]
Cells([color=crimson]1[/color], ch).Resize(rr, [color=crimson]1[/color]).DataSeries
Range(Cells([color=crimson]1[/color], ch), Cells(rr, ch + [color=crimson]2[/color])).Sort key1:=Cells([color=crimson]1[/color], ch + [color=crimson]1[/color]), order1:=xlAscending, Header:=xlYes
vx = Range(Cells([color=crimson]1[/color], ch + [color=crimson]1[/color]), Cells(rr + [color=crimson]1[/color], ch + [color=crimson]1[/color])).Value
[B][color=Royalblue]For[/color][/B] f = [color=crimson]2[/color] [B][color=Royalblue]To[/color][/B] UBound(vx, [color=crimson]1[/color]) - [color=crimson]1[/color]
g = f
[B][color=Royalblue]If[/color][/B] vx(f, [color=crimson]1[/color]) = [color=brown]""[/color] [B][color=Royalblue]Then[/color][/B] [B][color=Royalblue]GoTo[/color][/B] [B][color=Royalblue]skip[/color][/B]
[B][color=Royalblue]Do[/color][/B] [B][color=Royalblue]While[/color][/B] vx(f, [color=crimson]1[/color]) = vx(f + [color=crimson]1[/color], [color=crimson]1[/color])
f = f + [color=crimson]1[/color]
[B][color=Royalblue]Loop[/color][/B]
[B][color=Royalblue]If[/color][/B] f = g [B][color=Royalblue]Then[/color][/B] [B][color=Royalblue]GoTo[/color][/B] [B][color=Royalblue]skip[/color][/B]:
[B][color=Royalblue]Set[/color][/B] rng = Range(Cells(g, ch + [color=crimson]2[/color]), Cells(f, ch + [color=crimson]2[/color]))
va = rng
[B][color=Royalblue]Set[/color][/B] d = CreateObject([color=brown]"scripting.dictionary"[/color])
[B][color=Royalblue]For[/color][/B] i = [color=crimson]1[/color] [B][color=Royalblue]To[/color][/B] f - g
z = va(i, [color=crimson]1[/color])
[B][color=Royalblue]If[/color][/B] d.Exists(z) [B][color=Royalblue]Then[/color][/B]
d(z) = d(z) & [color=brown]","[/color] & i
[B][color=Royalblue]ElseIf[/color][/B] d.Exists(-z) [B][color=Royalblue]Then[/color][/B]
s = Split(d(-z), [color=brown]","[/color])
m = s(UBound(s))
va(i, [color=crimson]1[/color]) = va(i, [color=crimson]1[/color]) & [color=brown]"#"[/color]
va(m, [color=crimson]1[/color]) = va(m, [color=crimson]1[/color]) & [color=brown]"#"[/color]
[B][color=Royalblue]If[/color][/B] UBound(s) = [color=crimson]0[/color] [B][color=Royalblue]Then[/color][/B]
d.Remove -z
[B][color=Royalblue]Else[/color][/B]
d(-z) = Left(d(-z), Len(d(-z)) - Len(m) - [color=crimson]1[/color])
[B][color=Royalblue]End[/color][/B] [B][color=Royalblue]If[/color][/B]
[B][color=Royalblue]Else[/color][/B]
d(z) = i
[B][color=Royalblue]End[/color][/B] [B][color=Royalblue]If[/color][/B]
[B][color=Royalblue]Next[/color][/B] i
rng = va
[B][color=Royalblue]skip[/color][/B]:
[B][color=Royalblue]Next[/color][/B] f
[B][color=Royalblue]Set[/color][/B] rng = Range(Cells([color=crimson]1[/color], ch + [color=crimson]2[/color]), Cells(rr, ch + [color=crimson]2[/color]))
Application.ReplaceFormat.Interior.Color = vbYellow
rng.Replace What:=[color=brown]"#"[/color], Replacement:=[color=brown]""[/color], _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=[B][color=Royalblue]True[/color][/B], _
SearchFormat:=[B][color=Royalblue]False[/color][/B], ReplaceFormat:=[B][color=Royalblue]True[/color][/B]
Range(Cells([color=crimson]1[/color], ch), Cells(rr, ch + [color=crimson]2[/color])).Sort key1:=Cells([color=crimson]1[/color], ch), order1:=xlAscending, Header:=xlYes
Range(Cells([color=crimson]2[/color], ch + [color=crimson]2[/color]), Cells(rr, ch + [color=crimson]2[/color])).Copy
Cells([color=crimson]2[/color], cn).PasteSpecial paste:=xlPasteFormats
[i][color=seagreen]'deleting helper column[/color][/i]
Range(Cells([color=crimson]1[/color], ch), Cells([color=crimson]1[/color], ch + [color=crimson]2[/color])).EntireColumn.Delete
Application.ScreenUpdating = [B][color=Royalblue]True[/color][/B]
[B][color=Royalblue]End[/color][/B] [B][color=Royalblue]Sub[/color][/B]