Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim wrkRng As Range
  2. Dim hChoice As Integer
  3. Dim choice As String
  4. Dim debugVar As Variant
  5. Dim qtt As Integer
  6.  
  7. Sub Highlight() 'Q1
  8.    On Error GoTo ErrHandler:
  9. 'Part A
  10.    ThisWorkbook.ActiveSheet.Cells.FormatConditions.Delete
  11. 'Part B
  12.    Set wrkRng = Range(Range("FirstP"), Range("FirstP").End(xlDown).End(xlToRight))
  13. 'Part C
  14.    hChoice = InputBox("Choose 1 to highlight a product name" & vbNewLine & "Choose 2 to highlight a quantity order value")
  15. 'Part D
  16.    If hChoice = 1 Then
  17. 'Part E
  18.        choice = InputBox("Which product would you like to highlight ?")
  19.         debugVar = wrkRng.Columns(1).Find(choice, , , xlWhole)
  20.         wrkRng.FormatConditions.Add Type:=xlExpression, Formula1:="=$B31=" & Chr(34) & choice & Chr(34) ' Changer le $B31 par la valeur relative du nom FirsProduct
  21.        wrkRng.FormatConditions(1).Interior.Color = vbYellow
  22. 'Part D
  23.    ElseIf hChoice = 2 Then
  24.         choice = InputBox("enter an inequality sign for the quantity highlight rule (<, >, <=, or >=)")
  25.             If Application.WorksheetFunction.Or(choice = "<", choice = ">", choice = "<=", choice = ">=") Then
  26.                 qtt = InputBox("Enter a numeric value for the quantity highlight rule")
  27. 'Part E
  28.                If Application.WorksheetFunction.Or(choice = "<", choice = "<=") Then
  29.                     If Application.WorksheetFunction.Min(wrkRng.Columns(2)) > qtt Then
  30.                         MsgBox ("The quantity you use for the highlight rule is strictly lower than the minimum of the quantity")
  31.                         Exit Sub
  32.                     End If
  33.                 Else
  34.                     If Application.WorksheetFunction.Max(wrkRng.Columns(2)) < qtt Then
  35.                         MsgBox ("The quantity you use for the highlight rule is strictly greater than the maximum of the quantity")
  36.                         Exit Sub
  37.                     End If
  38.                 End If
  39.                 'We are supposed to be here only if there is no greater value max and lower value than min depending of user input
  40. 'Part F
  41.                wrkRng.FormatConditions.Add Type:=xlExpression, Formula1:="=$C31" & choice & qtt   ' Changer le $C31 par la valeur relative du nom FirsProduct"
  42.                wrkRng.FormatConditions(1).Interior.Color = vbYellow
  43.             Else
  44.                 Exit Sub
  45.             End If
  46.     Else
  47.         MsgBox ("Your choice need to be between 1 and 2")
  48.     End If
  49.    
  50.     Exit Sub
  51.    
  52. ErrHandler:
  53.     MsgBox ("Enter a valid product name")
  54.     Exit Sub
  55. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement