Select by Value

Input boxes will prompt for the minimum and maximum values to be selected.

Sub SelectBetweenValues()
 On Error Resume Next
 Application.ScreenUpdating = False
 Dim c As Range
 Dim myValue1 As Long
 Dim myValue2 As Long
 Dim r As Long
 Dim myArea As Range
 Dim myRange As Range
 Set myArea = ActiveSheet.UsedRange
 myValue1 = InputBox("Please enter the minimum number")
 myValue2 = InputBox("Please enter the maximum number")
 For Each c In myArea
  If c.Value >= myValue1 And c.Value <= myValue2 Then
   If r = 0 Then
    Set myRange = c
    r = 1
   Else
    Set myRange = Union(myRange, c)
   End If
  End If
 Next c
 myRange.Select
 Application.ScreenUpdating = True
End Sub



© Copyright andrewsexceltips.net All Rights Reserved.