Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub Highlight()
- '' line 5
- Cells.FormatConditions.Delete
- '' line 6
- Dim pTable As Range
- Set pTable = Range(Range("FirstP"), Range("FirstP").End(xlDown).End(xlToRight))
- '' line 7
- Dim hLight As Integer
- hLight = InputBox( _
- "enter one of the following choices to:" & vbNewLine _
- & "1: highlight product name" & vbNewLine _
- & "2: highlight quantity order vals", "enter 1 or 2", 1)
- '' line 8
- If hLight = 1 Then
- Dim pName1 As String
- pName1 = InputBox( _
- "enter the name of the product you would like to highlight", _
- "product name", "mug")
- '' line 9/10
- If pTable.Columns(1).Find(pName1, lookat:=xlWhole) Is Nothing Then
- '' line 11
- MsgBox "the product " & pName1 & " was not found", vbCritical, Error
- Exit Sub
- Else
- '' line 12/13
- pTable.Select
- With Selection
- .FormatConditions.Add Type:=xlExpression, Formula1:="= $b31 = " & Chr(34) & pName1 & Chr(34)
- .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
- .FormatConditions(1).Interior.Color = vbYellow
- .FormatConditions(1).StopIfTrue = False
- End With
- Range("E35").Select
- End If
- '' line 14
- ElseIf hLight = 2 Then
- Dim valSign As String
- valSign = InputBox("Enter a ""<"" or "">"" for your rules", "ineqaulity sign", "<")
- '' line 15
- If valSign <> "<" And valSign <> ">" Then
- '' line 16
- MsgBox "please enter a real inequality sign", vbCritical, "error"
- Exit Sub
- End If
- '' line 17
- Dim valNum As Double
- valNum = InputBox("enter a number to compare to the table", "enter a value", 5)
- '' line 18
- If valSign = "<" And valNum < Application.WorksheetFunction.Min(pTable.Columns(2)) Then
- MsgBox "none of the values in the table are less than " & valNum, vbCritical, "error"
- Exit Sub
- ElseIf valSign = ">" And valNum > Application.WorksheetFunction.Max(pTable.Columns(2)) Then
- MsgBox "none of the values in the table are greater than " & valNum, vbCritical, "error"
- Exit Sub
- Else
- '' line 23
- pTable.Select
- With Selection
- .FormatConditions.Add Type:=xlExpression, Formula1:="= $c31 " & valSign & valNum
- .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
- .FormatConditions(1).Interior.Color = vbYellow
- .FormatConditions(1).StopIfTrue = False
- End With
- Range("E35").Select
- End If
- '' line 24
- Else
- MsgBox "that is not a 1 or a 2 please try again", vbCritical, "error"
- Exit Sub
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement