Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim wrkRng As Range
- Dim hChoice As Integer
- Dim choice As String
- Dim debugVar As Variant
- Dim qtt As Integer
- Sub Highlight() 'Q1
- On Error GoTo ErrHandler:
- 'Part A
- ThisWorkbook.ActiveSheet.Cells.FormatConditions.Delete
- 'Part B
- Set wrkRng = Range(Range("FirstP"), Range("FirstP").End(xlDown).End(xlToRight))
- 'Part C
- hChoice = InputBox("Choose 1 to highlight a product name" & vbNewLine & "Choose 2 to highlight a quantity order value")
- 'Part D
- If hChoice = 1 Then
- 'Part E
- choice = InputBox("Which product would you like to highlight ?")
- debugVar = wrkRng.Columns(1).Find(choice, , , xlWhole)
- wrkRng.FormatConditions.Add Type:=xlExpression, Formula1:="=$B31=" & Chr(34) & choice & Chr(34) ' Changer le $B31 par la valeur relative du nom FirsProduct
- wrkRng.FormatConditions(1).Interior.Color = vbYellow
- 'Part D
- ElseIf hChoice = 2 Then
- choice = InputBox("enter an inequality sign for the quantity highlight rule (<, >, <=, or >=)")
- If Application.WorksheetFunction.Or(choice = "<", choice = ">", choice = "<=", choice = ">=") Then
- qtt = InputBox("Enter a numeric value for the quantity highlight rule")
- 'Part E
- If Application.WorksheetFunction.Or(choice = "<", choice = "<=") Then
- If Application.WorksheetFunction.Min(wrkRng.Columns(2)) > qtt Then
- MsgBox ("The quantity you use for the highlight rule is strictly lower than the minimum of the quantity")
- Exit Sub
- End If
- Else
- If Application.WorksheetFunction.Max(wrkRng.Columns(2)) < qtt Then
- MsgBox ("The quantity you use for the highlight rule is strictly greater than the maximum of the quantity")
- Exit Sub
- End If
- End If
- 'We are supposed to be here only if there is no greater value max and lower value than min depending of user input
- 'Part F
- wrkRng.FormatConditions.Add Type:=xlExpression, Formula1:="=$C31" & choice & qtt ' Changer le $C31 par la valeur relative du nom FirsProduct"
- wrkRng.FormatConditions(1).Interior.Color = vbYellow
- Else
- Exit Sub
- End If
- Else
- MsgBox ("Your choice need to be between 1 and 2")
- End If
- Exit Sub
- ErrHandler:
- MsgBox ("Enter a valid product name")
- Exit Sub
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement