Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CountLarge()
- Dim cell As Range, nLarge As Long
- Dim userValue As Integer
- Dim StartTime As Double
- Dim seconds As Double
- Dim test As String
- Dim rngFullRange
- Do ' This loop asks the user to enter a value b/w 0-240
- userValue = InputBox("Provide a value between 0 to 240")
- Loop Until userValue < 240 And userValue > 0
- With Range("B2")
- Range(.Offset(0, 1), .End(xlDown).End(xlToRight)).Name = "DataRange"
- End With
- Set rngFullRange = Worksheets("Data").Range("DataRange")
- For Each cell In rngFullRange ' loops each cell in Data to find values more than user input
- If IsNumeric(cell) = True Then
- If cell.Value > userValue Then
- cell.Font.Bold = True ' Bolds the values that are larger that user input
- cell.Font.Color = vbRed ' changes font color to red when values are larger that user input
- nLarge = nLarge + 1 ' keeps count of values larger than user input
- End If
- End If
- Next
- MsgBox nLarge & " cells in the data range have a quantity larger than " & userValue & ""
- Application.ScreenUpdating = True
- seconds = Round(Timer - StartTime, 2)
- MsgBox "This code ran successfully in " & seconds & " seconds"
- test = "This code ran successfully in " & seconds & " seconds"
- Worksheets("Start").Range("A3").Value = test 'pastes the value of timer in A3
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement