Hi all,
Yesterday I got help with some vba code and it seemed to work. However today it keeps giving the same error (91, Object variable or With block variable not set). This seems to go wrong when I try to select all values from C - N (function SelectByValue1). Does anyone know the answer to this?
Furthermore, if there are no values to select, it crashes as well....
HELP!
Option Explicit
Sub SelectByValue(Rng1 As Range, MinimunValue As Double, MaximumValue As Double)
Dim MyRange As Range
Dim Cell As Object
'Check every cell in the range for matching criteria.
For Each Cell In Rng1
If Cell.Value >= MinimunValue And Cell.Value <= MaximumValue Then
If MyRange Is Nothing Then
Set MyRange = Range(Cell.Address)
Else
Set MyRange = Union(MyRange, Range(Cell.Address))
End If
End If
Next
'Select the new range of only matching criteria
MyRange.Select
End Sub
Sub SelectByValue1(Rng1 As Range, MinimunValue As String, MaximumValue As String)
Dim MyRange As Range
Dim Cell As Object
'Check every cell in the range for matching criteria.
For Each Cell In Rng1
If Cell.Value >= MinimunValue And Cell.Value <= MaximumValue Then
If Len(Cell) = 1 _
And Not Cell.HasFormula Then
If MyRange Is Nothing Then
Set MyRange = Range(Cell.Address)
Else
Set MyRange = Union(MyRange, Range(Cell.Address))
End If
End If
End If
Next
'Select the new range of only matching criteria
MyRange.Select
End Sub
Private Sub CommandButton1_Click()
Call Verwijder
Controle.Hide
End Sub
Private Sub Verwijder()
'Call the macro and pass all the required variables to it.
Call SelectByValue1(Range("D4:IQ1000"), "C", "N")
Selection.ClearContents
Range("A1").Select
Call SelectByValue(Range("D4:IQ1000"), 10, 10000)
Selection.ClearContents
Controle.Hide
End Sub
Private Sub CommandButton3_Click()
Controle.Hide
End Sub
Bookmarks