Hello,
This should be a very simple problem for most I think. I'm just not seeing the problem. So basically I need to sort thru the data on columns A:B on Tester and pick out the unique part numbers and their cost and then check column C to see if the part number exists there, if it does not, then add it to column C along with the cost in column D. But for some reason, while the first 2 part numbers seem to work fine, it then starts adding duplicates to column C and I'm at my wits end to figure out why my code is allowing this to happen. Any help is greatly appreciated.
Option Explicit
Dim pWB As Workbook, wsHome As Worksheet, wsText As Worksheet
Sub Runner()
Set pWB = Workbooks(ThisWorkbook.Name)
Set wsHome = pWB.Worksheets("Home")
Set wsText = pWB.Worksheets("Texter")
'Start Loop
wsText.Columns("C:D").ColumnWidth = 20
wsText.Columns("C:D").HorizontalAlignment = xlCenter
wsText.Range("$C$1").Value = "Part Number"
wsText.Range("$D$1").Value = "Part Cost"
Dim I, C, A As Integer
Dim p_Num As Range
Dim xNum, xCos As String
A = wsText.Range("$A" & Rows.Count).End(xlUp).Row
C = wsText.Range("$C" & Rows.Count).End(xlUp).Row
For I = A To 2 Step -1
If wsText.Range("$A$" & I).Value = "Mfr" Then
xNum = wsText.Range("$B$" & Val(I + 1)).Value
xCos = wsText.Range("$B$" & Val(I + 5)).Value
C = wsText.Range("$C" & Rows.Count).End(xlUp).Row
Set p_Num = wsText.Range("$C$1:$C$" & C).Find(xNum, , xlValues, xlWhole)
If p_Num Is Nothing Then
wsText.Range("$C$" & Val(C + 1)).Value = xNum
wsText.Range("$D$" & Val(C + 1)).Value = xCos
End If
End If
Next I
End Sub
Bookmarks