Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub Highlight()
  4.    
  5.     '' line 5
  6.    Cells.FormatConditions.Delete
  7.        
  8.     '' line 6
  9.    Dim pTable As Range
  10.     Set pTable = Range(Range("FirstP"), Range("FirstP").End(xlDown).End(xlToRight))
  11.    
  12.     '' line 7
  13.    Dim hLight As Integer
  14.    
  15.     hLight = InputBox( _
  16.         "enter one of the following choices to:" & vbNewLine _
  17.         & "1: highlight product name" & vbNewLine _
  18.         & "2: highlight quantity order vals", "enter 1 or 2", 1)
  19.        
  20.     '' line 8
  21.    If hLight = 1 Then
  22.    
  23.         Dim pName1 As String
  24.         pName1 = InputBox( _
  25.         "enter the name of the product you would like to highlight", _
  26.         "product name", "mug")
  27.        
  28.         '' line 9/10
  29.        If pTable.Columns(1).Find(pName1, lookat:=xlWhole) Is Nothing Then
  30.             '' line 11
  31.            MsgBox "the product " & pName1 & " was not found", vbCritical, Error
  32.             Exit Sub
  33.         Else
  34.             '' line 12/13
  35.            pTable.Select
  36.             With Selection
  37.                 .FormatConditions.Add Type:=xlExpression, Formula1:="= $b31 = " & Chr(34) & pName1 & Chr(34)
  38.                 .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
  39.                 .FormatConditions(1).Interior.Color = vbYellow
  40.                 .FormatConditions(1).StopIfTrue = False
  41.             End With
  42.             Range("E35").Select
  43.         End If
  44.        
  45.    
  46.     '' line 14
  47.    ElseIf hLight = 2 Then
  48.    
  49.         Dim valSign As String
  50.        
  51.         valSign = InputBox("Enter a ""<"" or "">"" for your rules", "ineqaulity sign", "<")
  52.        
  53.         '' line 15
  54.        If valSign <> "<" And valSign <> ">" Then
  55.             '' line 16
  56.            MsgBox "please enter a real inequality sign", vbCritical, "error"
  57.             Exit Sub
  58.         End If
  59.        
  60.         '' line 17
  61.        Dim valNum As Double
  62.         valNum = InputBox("enter a number to compare to the table", "enter a value", 5)
  63.        
  64.         '' line 18
  65.        If valSign = "<" And valNum < Application.WorksheetFunction.Min(pTable.Columns(2)) Then
  66.             MsgBox "none of the values in the table are less than " & valNum, vbCritical, "error"
  67.             Exit Sub
  68.         ElseIf valSign = ">" And valNum > Application.WorksheetFunction.Max(pTable.Columns(2)) Then
  69.             MsgBox "none of the values in the table are greater than " & valNum, vbCritical, "error"
  70.             Exit Sub
  71.         Else
  72.             '' line 23
  73.            pTable.Select
  74.             With Selection
  75.                 .FormatConditions.Add Type:=xlExpression, Formula1:="= $c31 " & valSign & valNum
  76.                 .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
  77.                 .FormatConditions(1).Interior.Color = vbYellow
  78.                 .FormatConditions(1).StopIfTrue = False
  79.             End With
  80.             Range("E35").Select
  81.         End If
  82.        
  83.        
  84.     '' line 24
  85.    Else
  86.         MsgBox "that is not a 1 or a 2 please try again", vbCritical, "error"
  87.         Exit Sub
  88.     End If
  89.  
  90. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement