I'm trying to set up some sheets to run invoicing and stock control for my business. I have an invoice template, the sheet is called "Shop" where col A rows 22 to 41 have stock codes and col B rows 22 to 41 have the quantities to be sold.
The script I need will find the value in Shop A22 in another sheet (called "Stock" between A5 & I1000) and update the quantity in stock which is held in col 5 and the quantity sold held in col 7.
At present I have this working in Excel using the two modules shown below but I don't know how to get them to work in Sheets.
Could anyone help please?
Thanks
Sub UpdateStockDetailsDjB()
Dim intRow As Integer
Dim intStk As Integer
Dim strPrd As String
' Serially process cells A22 thru A41
intRow = 22
Do
If Worksheets("Shop").Cells(intRow, 1).Value = "" Then
Exit Do
End If
Rem strPrd = Left(Trim(Worksheets("Shop").Cells(intRow, 1).Value), 5)
strPrd = (Worksheets("Shop").Cells(intRow, 1).Value)
intStk = fncFindPrdStk(strPrd) ' Stock Code row in ShopStock sheet
Worksheets("Stock").Cells(intStk, 5).Value = Worksheets("Stock").Cells(intStk, 5).Value - Worksheets("Shop").Cells(intRow, 2).Value ' Update Qty in Stock
Worksheets("Stock").Cells(intStk, 7).Value = Worksheets("Stock").Cells(intStk, 7).Value + Worksheets("Shop").Cells(intRow, 2).Value ' Update Used / Sold
If intRow = 41 Then
Exit Do
End If
intRow = intRow + 1
Loop
' End
Call Clearhop
End Sub
Function fncFindPrdStk(strPrd As String) As Variant
Dim intRow As Integer
' Find Stock Code row in Stock sheet cells A3 thru A1010
intRow = 3
Do
If Trim(Worksheets("Stock").Cells(intRow, 1).Value) = strPrd Then
Exit Do
End If
If intRow = 1510 Then
MsgBox "Stock Code MISSING: " & strPrd, vbCritical
Exit Do
End If
intRow = intRow + 1
Loop
' Return Stock Code row
fncFindPrdStk = intRow
End Function