Advertisement
Guest User

Cp212

a guest
Oct 18th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. Sub CountLarge()
  2.     Dim cell As Range, nLarge As Long
  3.     Dim userValue As Integer
  4.     Dim StartTime As Double
  5.     Dim seconds As Double
  6.     Dim test As String
  7.     Dim rngFullRange
  8.    
  9.     Do ' This loop asks the user to enter a value b/w 0-240
  10.        userValue = InputBox("Provide a value between 0 to 240")
  11.    Loop Until userValue < 240 And userValue > 0
  12.    
  13.    With Range("B2")
  14.    Range(.Offset(0, 1), .End(xlDown).End(xlToRight)).Name = "DataRange"
  15.    End With
  16.    Set rngFullRange = Worksheets("Data").Range("DataRange")
  17.    
  18.    For Each cell In rngFullRange ' loops each cell in Data to find values more than user input
  19.         If IsNumeric(cell) = True Then
  20.             If cell.Value > userValue Then
  21.                 cell.Font.Bold = True ' Bolds the values that are larger that user input
  22.                cell.Font.Color = vbRed ' changes font color to red when values are larger that user input
  23.                 nLarge = nLarge + 1 ' keeps count of values larger than user input
  24.            End If
  25.        End If
  26.    Next
  27.    MsgBox nLarge & " cells in the data range have a quantity larger than " & userValue & ""
  28.    
  29.    Application.ScreenUpdating = True
  30.    seconds = Round(Timer - StartTime, 2)
  31.    MsgBox "This code ran successfully in " & seconds & " seconds"
  32.    test = "This code ran successfully in " & seconds & " seconds"
  33.    Worksheets("Start").Range("A3").Value = test 'pastes the value of timer in A3
  34.    
  35. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement