Results 1 to 1 of 1

error 91 with selection

Threaded View

  1. #1
    Registered User
    Join Date
    11-12-2007
    Location
    Dordrecht, Netherlands
    MS-Off Ver
    2016
    Posts
    35

    error 91 with selection

    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
    Last edited by VBA Noob; 11-15-2007 at 03:56 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1