Stock Update Macro

iisailor

Board Regular
Joined
Feb 18, 2009
Messages
58
Hi everyone.
Currently im working on a macro that, in short, will read relevant cells of a worksheet (which is basically an order form) then compare them against another workbook (which is essentially a stock list). To do this it must read the code number for each part (this is stored in cells A, B & C of each row) in the first workbook then try to match this to the code numbers in the Stock workbook, in cells B, C & D.
One big obstacle ive found with this is that these code numbers arent in a neat list starting on the first row. They start anywhere from the 6th row down to the twentieth row down. In my code you'll see ive tried to use the VBA code that figures out what the last cell in a column is and then ive tried to set that as the range but so far to no avail.
If it finds a match i then wish it to check the quantity. In Parts workbook this is in column F and in Stock its in column L. I need the macro to work out which is greater than which then subtract the smaller. Once this is done it must update both of the affected cells in both of the workbooks.
Once completed and the quantity values have been updated the macro must move on to the next part and do all parts in the workbook.

Note: I use the word workbook because once one sheet in Parts has been completed it must move onto the next sheet, then repeat, until all sheeets are done. The Stock workbook only has one sheet.

Below is what little poor code ive come up with already. I do apologise for the quality, im still getting into excel and VBA.

The Code:
Sub StockCheck()

Dim PartSearch As Integer
'On Error GoTo Err_Execute
PartSearch = 1

While Len(Range("A" & CStr(PartSearch)).Value) < Range("A65536").End(xlUp).Select
If Range("F" & CStr(PartSearch)).Value > 0 Then
Cells.Range("A:C" & "F").Select
Selection.Copy
Workbooks("Kiverco Stocking System TEST").Activate
Sheets("Stock Items").Select
Cells.Range("W1:Z1").ActiveSheet.Paste
End If
If Range("B" & CStr(PartSearch)).Value = Range("W1") Then
If Range("C" & CStr(PartSearch)).Value = Range("X1") Then
If Range("D" & CStr(PartSearch)).Value = Range("Y1") Then
If Range("L" & CStr(PartSearch)).Value > Range("Z1").Value Then
'If Range("L").Value > Range("Z1").Value Then
Range("L") = Range("L") - Range("Z1")
Range("Z1") = 0
End If
Else
If Range("L" & CStr(PartSearch)).Value < Range("Z1").Value Then
Range("Z1") = ("Z1") - ("L")
Range("L") = 0
Else
Range("Z1") = 0
Range("L") = 0
End If
End If
End If
End If
'Err_Execute:
' MsgBox "An error occurred."

Cells.Range("Z1").Copy
Workbooks("Kiverco Parts Lists TEST").Activate
Sheets("1025 - Magnet Frames").Select
' Cells.Range("L").ActiveSheet.Paste
PartSearch = PartSearch + 1
Wend

End Sub


If anyone can help this would be genuinely appreciated. Also if the workbooks are needed to help i can create an example.
Much thanks in advance
Chris
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi guys, ive continued to work on with this little job but havent really got much more. My code is now as follows:

Sub StockCheck()
Dim PartSearch As Integer
Dim Last As Range
Dim Source As Range
'On Error GoTo Err_Execute
PartSearch = 2
Set Last = Range("A65536").End(xlUp)
While Len(Range("B" & CStr(PartSearch)).Value) <= Last
If Range("F" & CStr(PartSearch)).Value > 0 Then
Rows(CStr(PartSearch) & ":" & CStr(PartSearch)).Select
'Set Source = Nothing
'Set Source = Range("A:C" & "F")
Selection.Copy
ActiveSheet.Paste Destination:=Workbooks("Kiverco Stocking System TEST").Worksheet("Stock Items").Cells("1, 26")

'Workbooks("Kiverco Stocking System TEST").Activate
'Sheets("Stock Items").Select
'Cells.Range("W1:Z1").ActiveSheet.Paste
End If
If Range("B" & CStr(PartSearch)).Value = Range("W1") Then
If Range("C" & CStr(PartSearch)).Value = Range("X1") Then
If Range("D" & CStr(PartSearch)).Value = Range("Y1") Then
If Range("L" & CStr(PartSearch)).Value > Range("Z1").Value Then
'If Range("L").Value > Range("Z1").Value Then
Range("L") = Range("L") - Range("Z1")
Range("Z1") = 0
End If
Else
If Range("L" & CStr(PartSearch)).Value < Range("Z1").Value Then
Range("Z1") = ("Z1") - ("L")
Range("L") = 0
Else
Range("Z1") = 0
Range("L") = 0
End If

End If
End If
End If
'Err_Execute:
' MsgBox "An error occurred."

Cells.Range("Z1").Copy
Workbooks("Kiverco Parts Lists TEST").Activate
Sheets("1025 - Magnet Frames").Select
PartSearch = PartSearch + 1
Wend

End Sub


Again any help would be appreciated, especially an overall overhaul where it'd be great if someone could guide me and tell me what i need to be doing.
Thanks in advance
Chris
 
Upvote 0
Sorry guys,
Quick update, its not much but i have fixed the beginning of the code with the line:
ActiveSheet.Paste Destination:=Workbooks("Kiverco Stocking System TEST").Worksheets("Stock Items").Cells(2100, 1)

Also note as opposed to copying everything to row 1 and column Z im now putting it on the last rows underneath all items in the Stocking System workbook. This is a smart move??:eek:
Thanks again
Chris
 
Upvote 0
hi all, just really trying to refresh this post in the forum. Im really quite stuck at the minute so any help at all would be greatly appreciated
Chris
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top