Hi All,
Hope somebody can help me with the following. I have an excel workbook with a sheet or part numbers and a sheet of qty's. The code should look at the part number and get the qty from the next sheet, and if the is two qty entries for that part then sum them. It works fine if there is just one entry in the qty sheet, but when there is multiple entries it never seems to exit the "findnext" loop.
Anyone any ideas?
Private Sub comprtstk_Click()
Dim search, Qty, searchcounter, writecounter, mycell, mynextcell, address, address2, FirstAddress
searchcounter = 2
writecounter = 2
'do loop until no more parts
Do Until Sheets("PARTDETAIL".Cells(searchcounter, 2) = ""
Qty = 0
'first part number
search = Worksheets("PARTDETAIL".Cells(searchcounter, 2)
'search for part number
With Sheets("STKDETAIL".Range("B1:B10000"
Set mycell = .Find(search)
If Not mycell Is Nothing Then
address = mycell.Row
FirstAddress = mycell.address
Qty = Worksheets("STKDETAIL".Cells(address, 3)
Set mynextcell = .FindNext(mycell)
If Not mynextcell Is Nothing And mynextcell.address <> FirstAddress Then
Do
Set mynextcell = .FindNext(mycell)
address2 = mynextcell.Row
Qty = Qty + Worksheets("STKDETAIL".Cells(address2, 3)
Loop While Not mynextcell Is Nothing Or mynextcell.address <> FirstAddress
End If
End If
Worksheets("partandstockdetail".Cells(writecounter, 1) = Worksheets("partdetail".Cells(searchcounter, 2)
Worksheets("partandstockdetail".Cells(writecounter, 2) = Worksheets("partdetail".Cells(searchcounter, 3) ' Des
Worksheets("partandstockdetail".Cells(writecounter, 3) = Worksheets("partdetail".Cells(searchcounter, 4) ' Supplier
Worksheets("partandstockdetail".Cells(writecounter, 4) = Qty ' Quantity
Worksheets("partandstockdetail".Cells(writecounter, 5) = Worksheets("partdetail".Cells(searchcounter, 5) ' Min
Worksheets("partandstockdetail".Cells(writecounter, 6) = Worksheets("partdetail".Cells(searchcounter, 6) ' Lead
Worksheets("partandstockdetail".Cells(writecounter, 7) = Worksheets("partdetail".Cells(searchcounter, 7) ' Batch
writecounter = writecounter + 1
End With
searchcounter = searchcounter + 1
Loop
End Sub
Hope somebody can help me with the following. I have an excel workbook with a sheet or part numbers and a sheet of qty's. The code should look at the part number and get the qty from the next sheet, and if the is two qty entries for that part then sum them. It works fine if there is just one entry in the qty sheet, but when there is multiple entries it never seems to exit the "findnext" loop.
Anyone any ideas?
Private Sub comprtstk_Click()
Dim search, Qty, searchcounter, writecounter, mycell, mynextcell, address, address2, FirstAddress
searchcounter = 2
writecounter = 2
'do loop until no more parts
Do Until Sheets("PARTDETAIL".Cells(searchcounter, 2) = ""
Qty = 0
'first part number
search = Worksheets("PARTDETAIL".Cells(searchcounter, 2)
'search for part number
With Sheets("STKDETAIL".Range("B1:B10000"
Set mycell = .Find(search)
If Not mycell Is Nothing Then
address = mycell.Row
FirstAddress = mycell.address
Qty = Worksheets("STKDETAIL".Cells(address, 3)
Set mynextcell = .FindNext(mycell)
If Not mynextcell Is Nothing And mynextcell.address <> FirstAddress Then
Do
Set mynextcell = .FindNext(mycell)
address2 = mynextcell.Row
Qty = Qty + Worksheets("STKDETAIL".Cells(address2, 3)
Loop While Not mynextcell Is Nothing Or mynextcell.address <> FirstAddress
End If
End If
Worksheets("partandstockdetail".Cells(writecounter, 1) = Worksheets("partdetail".Cells(searchcounter, 2)
Worksheets("partandstockdetail".Cells(writecounter, 2) = Worksheets("partdetail".Cells(searchcounter, 3) ' Des
Worksheets("partandstockdetail".Cells(writecounter, 3) = Worksheets("partdetail".Cells(searchcounter, 4) ' Supplier
Worksheets("partandstockdetail".Cells(writecounter, 4) = Qty ' Quantity
Worksheets("partandstockdetail".Cells(writecounter, 5) = Worksheets("partdetail".Cells(searchcounter, 5) ' Min
Worksheets("partandstockdetail".Cells(writecounter, 6) = Worksheets("partdetail".Cells(searchcounter, 6) ' Lead
Worksheets("partandstockdetail".Cells(writecounter, 7) = Worksheets("partdetail".Cells(searchcounter, 7) ' Batch
writecounter = writecounter + 1
End With
searchcounter = searchcounter + 1
Loop
End Sub