I am working on a project that is as follows below. I am having a hard time with the CommandButton portions of the below. I know what I want to do in English but can't seem to type it out into VBA. I am storing the data of the table into multiple arrays.
UserForm setup is as follows and looks like the attached
:
• An employee will select one of the 12 items from a ComboBox and type the number of units requested in a TextBox.
• Next, the employee will click a CommandButton and the program will attempt to subtract the number of units requested from the existing inventory.
◦ If the number of units requested is less than or equal to the number of units still in stock in column C, the value in column C will be updated and this updated value will be displayed on the UserForm in a TextBox. If the updated value is less than 5, a message box will tell the employee that the store is running out of that item. The message box should include the catalog number and number of items in stock.
◦ However, if the number of units requested is greater than the number of units still in stock in column C, then a message box will tell the employee that the order cannot be met. The value in column C will not be updated.
• There will be a second CommandButton that only determines the number of units in stock for the item selected in the ComboBox. This CommandButton will not update column C.
• There will be a third CommandButton that quits the UserForm.
Table looks like the following in Columns A-C and Rows 1-16:
<tbody>
</tbody>
Current code is:
Option Explicit
Private Sub Combo_Item_Change()
End Sub
Private Sub Combo_Item_DropButt*******()
Combo_Item.List = Array("Paper - wide rule - 100 sheets", "Paper - wide rule - 200 sheets", "Paper - wide rule - 500 sheets", "Pencils - #2 - 10 pack", "Pencils - #2 - 20 pack", "Highlighters - yellow - 1 pack", "Highlighters - yellow - 3 pack", "Highlighters - pink - 1 pack", "Highlighters - pink - 3 pack", "Paper clips - small - 100 count", "Paper clips - small - 200 count", "Paper clips - large - 100 count")
End Sub
Private Sub Command_ChkStock_Click()
End Sub
Private Sub Command_Quit_Click()
Unload UserForm1
End Sub
Private Sub Command_Run_Click()
Dim rNum As Integer, cNum As Integer
Dim inventory() As String
Dim item() As String
Dim catNum() As String
Dim itemcnt() As String
Dim i As Integer, j As Integer
Dim UnitsReq As String, ItemName As String
rNum = Worksheets("Sheet2").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
cNum = Cells(1, Columns.Count).End(xlToLeft).Column
UnitsReq = Text_UnitsReq.Value 'value of units requested placed in text box
ItemName = Combo_Item.Value 'value of item chosen from combo box
ReDim inventory(rNum, cNum) As String 'pull all detail into an array
ReDim item(rNum, 0) As String 'pull column A into an array of items
ReDim catNum(rNum, 1) As String 'pull column B into an array of catalog numbers
ReDim itemcnt(rNum, 2) As String 'pull column C into an array of items in stock
Range("A2").Select
For i = 1 To rNum
For j = 1 To cNum
inventory(i, j) = ActiveCell.Offset(i - 1, j - 1).Value
item(i, 0) = ActiveCell.Offset(i - 1, 0).Value
catNum(i, 1) = ActiveCell.Offset(i - 1, 1).Value
itemcnt(i, 2) = ActiveCell.Offset(i - 1, 2).Value
Next j
Next i
End Sub
Anyone want to try this brain teaser out? Any help is appreciated!
UserForm setup is as follows and looks like the attached
• An employee will select one of the 12 items from a ComboBox and type the number of units requested in a TextBox.
• Next, the employee will click a CommandButton and the program will attempt to subtract the number of units requested from the existing inventory.
◦ If the number of units requested is less than or equal to the number of units still in stock in column C, the value in column C will be updated and this updated value will be displayed on the UserForm in a TextBox. If the updated value is less than 5, a message box will tell the employee that the store is running out of that item. The message box should include the catalog number and number of items in stock.
◦ However, if the number of units requested is greater than the number of units still in stock in column C, then a message box will tell the employee that the order cannot be met. The value in column C will not be updated.
• There will be a second CommandButton that only determines the number of units in stock for the item selected in the ComboBox. This CommandButton will not update column C.
• There will be a third CommandButton that quits the UserForm.
Table looks like the following in Columns A-C and Rows 1-16:
Item Name | Item Catalog Number | Units In Stock |
Paper - wide rule - 100 sheets | 10010 | 17 |
Paper - wide rule - 200 sheets | 10020 | 23 |
Paper - wide rule - 500 sheets | 10030 | 10 |
Pencils - #2 - 10 pack | 10110 | 19 |
Pencils - #2 - 20 pack | 10120 | 9 |
Highlighters - yellow - 1 pack | 10210 | 20 |
Highlighters - yellow - 3 pack | 10220 | 34 |
Highlighters - pink - 1 pack | 10230 | 21 |
Highlighters - pink - 3 pack | 10240 | 50 |
Paper clips - small - 100 count | 10310 | 28 |
Paper clips - small - 200 count | 10320 | 7 |
Paper clips - large - 100 count | 10330 | 12 |
<tbody>
</tbody>
Current code is:
Option Explicit
Private Sub Combo_Item_Change()
End Sub
Private Sub Combo_Item_DropButt*******()
Combo_Item.List = Array("Paper - wide rule - 100 sheets", "Paper - wide rule - 200 sheets", "Paper - wide rule - 500 sheets", "Pencils - #2 - 10 pack", "Pencils - #2 - 20 pack", "Highlighters - yellow - 1 pack", "Highlighters - yellow - 3 pack", "Highlighters - pink - 1 pack", "Highlighters - pink - 3 pack", "Paper clips - small - 100 count", "Paper clips - small - 200 count", "Paper clips - large - 100 count")
End Sub
Private Sub Command_ChkStock_Click()
End Sub
Private Sub Command_Quit_Click()
Unload UserForm1
End Sub
Private Sub Command_Run_Click()
Dim rNum As Integer, cNum As Integer
Dim inventory() As String
Dim item() As String
Dim catNum() As String
Dim itemcnt() As String
Dim i As Integer, j As Integer
Dim UnitsReq As String, ItemName As String
rNum = Worksheets("Sheet2").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
cNum = Cells(1, Columns.Count).End(xlToLeft).Column
UnitsReq = Text_UnitsReq.Value 'value of units requested placed in text box
ItemName = Combo_Item.Value 'value of item chosen from combo box
ReDim inventory(rNum, cNum) As String 'pull all detail into an array
ReDim item(rNum, 0) As String 'pull column A into an array of items
ReDim catNum(rNum, 1) As String 'pull column B into an array of catalog numbers
ReDim itemcnt(rNum, 2) As String 'pull column C into an array of items in stock
Range("A2").Select
For i = 1 To rNum
For j = 1 To cNum
inventory(i, j) = ActiveCell.Offset(i - 1, j - 1).Value
item(i, 0) = ActiveCell.Offset(i - 1, 0).Value
catNum(i, 1) = ActiveCell.Offset(i - 1, 1).Value
itemcnt(i, 2) = ActiveCell.Offset(i - 1, 2).Value
Next j
Next i
End Sub
Anyone want to try this brain teaser out? Any help is appreciated!