It didn't work on my end. I am honestly very new with VBA so my entire spreadsheet needs a lot of work. That is one component of the spreadsheet and it is located at the top of the sheet. The purpose of the sheet is for the end user to input number of customers and painting ID and the worksheet will automatically generate the remaining inventory. If the inventory is below a minimum level, the user will be notified through a message. The entire spreadsheet is not working but I figured I would take the errors step by step in order to complete the project. The painting ID's are treated similarly to number of customers as the ID's range between 100-110. The code is posted below:
Option Explicit
Dim sngCustomers As Single
Dim sngPainting As Single
Dim sngCanvases As Single
Dim sngAprons As Single
Dim intWhite As Integer
Dim intYellow As Integer
Dim intOrange As Integer
Dim intRed As Integer
Dim intPurple As Integer
Dim intBlue As Integer
Dim intGreen As Integer
Dim intFlesh As Integer
Dim intSienna As Integer
Dim intBrown As Integer
Dim intBlack As Integer
Private Sub cmdReset_Click()
Range("Activity").Select
Selection.ClearContents
Range("Customers").Select
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim strCurrentCell As String
Dim strB3 As String
Dim strB4 As String
Dim strMessage As String
strCurrentCell = ActiveCell.Address
strB3 = "$B$3"
strB4 = "$B$4"
'Data entry controls
strMessage = "Check your entry for Customers," _
& " there can only be up to twenty" _
& " customers per class period."
If strCurrentCell = strB3 Then
'Assignment of Values from Work Sheet Variable
sngCustomers = Range("Customers").Value
If sngCustomers > 20 Or sngCustomers = "" Then
MsgBox strMessage, vbOKOnly, "Error"
Range("Customers").Value = ""
Range("Customers").Select
Exit Sub
End If
End If
strMessage = "Check your entry for Painting," _
& " the options range from 100-110."
If strCurrentCell = strB4 Then
'Assignment of Values from Work Sheet Variable
sngPainting = Range("Painting").Value
If sngPainting > 110 Or sngPainting < 100 Then
MsgBox strMessage, vbOKOnly, "Error"
Range("Painting").Select
Exit Sub
End If
End If
If strCurrentCell = strB4 Then
'Assignment of values from worksheet to variables
sngCustomers = Range("Customers").Value
sngPainting = Range("Painting").Value
sngCanvases = Range("Canvases").Value
sngAprons = Range("Aprons").Value
intWhite = Range("White").Value
intYellow = Range("Yellow").Value
intOrange = Range("Orange").Value
intRed = Range("Red").Value
intPurple = Range("Purple").Value
intBlue = Range("Blue").Value
intGreen = Range("Green").Value
intFlesh = Range("Flesh").Value
intSienna = Range("Sienna").Value
intBrown = Range("Brown").Value
intBlack = Range("Black").Value
'Calculation of Inventory based on Customers
sngCanvases = sngCanvases - sngCustomers
sngAprons = sngAprons - sngCustomers
'Calculation of Inventory based on Painting
If sngPainting = 100 Then
intWhite = intWhite - 0.5
intPurple = intPurple - 0.5
intBlue = intBlue - 0.5
intGreen = intGreen - 0.5
intBrown = intBrown - 0.5
intBlack = intBlack - 0.5
End If
If sngPainting = 101 Then
intYellow = intYellow - 0.5
intRed = intRed - 0.5
intPurple = intPurple - 0.5
intBlue = intBlue - 0.5
intBrown = intBrown - 0.5
End If
If sngPainting = 102 Then
intWhite = intWhite - 0.5
intYellow = intYellow - 0.5
intOrange = intOrange - 0.5
intRed = intRed - 0.5
intPurple = intPurple - 0.5
intFlesh = intFlesh - 0.5
intSienna = intSienna - 0.5
End If
If sngPainting = 103 Then
intRed = intRed - 0.5
intPurple = intPurple - 0.5
intSienna = intSienna - 0.5
intBrown = intBrown - 0.5
End If
If sngPainting = 104 Then
intWhite = intWhite - 0.5
intYellow = intYellow - 0.5
intOrange = intOrange - 0.5
intBlue = intBlue - 0.5
intFlesh = intFlesh - 0.5
intBlack = intBlack - 0.5
End If
If sngPainting = 105 Then
intWhite = intWhite - 0.5
intBlue = intBlue - 0.5
intGreen = intGreen - 0.5
intSienna = intSienna - 0.5
intBrown = intBrown - 0.5
intBlack = intBlack - 0.5
End If
If sngPainting = 106 Then
intWhite = intWhite - 0.5
intRed = intRed - 0.5
intBrown = intBrown - 0.5
End If
If sngPainting = 107 Then
intWhite = intWhite - 0.5
intYellow = intYellow - 0.5
intOrange = intOrange - 0.5
intRed = intRed - 0.5
intBlue = intBlue - 0.5
intGreen = intGreen - 0.5
intSienna = intSienna - 0.5
End If
If sngPainting = 108 Then
intWhite = intWhite - 0.5
intOrange = intOrange - 0.5
intRed = intRed - 0.5
intBlue = intBlue - 0.5
intGreen = intGreen - 0.5
intFlesh = intFlesh - 0.5
End If
If sngPainting = 109 Then
intWhite = intWhite - 0.5
intYellow = intYellow - 0.5
intRed = intRed - 0.5
intPurple = intPurple - 0.5
intBlue = intBlue - 0.5
End If
If sngPainting = 110 Then
intWhite = intWhite - 0.5
intYellow = intYellow - 0.5
intBlue = intBlue - 0.5
intBlack = intBlack - 0.5
End If
'Advice regarding minimum inventory points
If sngCanvases < 400 Then
MsgBox "Reorder Canvases"
End If
If sngAprons < 400 Then
MsgBox "Reorder Aprons"
End If
If intWhite < 128 Then
MsgBox "Reorder White Paint"
End If
If intYellow < 128 Then
MsgBox "Reorder Yellow Paint"
End If
If intOrange < 128 Then
MsgBox "Reorder Orange Paint"
End If
If intRed < 128 Then
MsgBox "Reorder Red Paint"
End If
If intPurple < 128 Then
MsgBox "Reorder Purple Paint"
End If
If intBlue < 128 Then
MsgBox "Reorder Blue Paint"
End If
If intGreen < 128 Then
MsgBox "Reorder Green Paint"
End If
If intFlesh < 128 Then
MsgBox "Reorder Flesh Paint"
End If
If intSienna < 128 Then
MsgBox "Reorder Sienna Paint"
End If
If intBrown < 128 Then
MsgBox "Reorder Brown Paint"
End If
If intBlack < 128 Then
MsgBox "Reorder Black Paint"
End If
End If
End Sub
Bookmarks