+ Reply to Thread
Results 1 to 2 of 2

runtime error 91 object variable or With block variable not set

Hybrid View

  1. #1
    Registered User
    Join Date
    11-15-2010
    Location
    Norway
    MS-Off Ver
    Office 11
    Posts
    17

    runtime error 91 object variable or With block variable not set

    'Drop Down liste 1
        Private Sub UserForm_Initialize()
        Sheets("Ark2").Select
        Dim ws As Worksheet
        Dim rCombo As Range
    
        'set a variable to the sheet with the list
        Set ws = Sheet2
        'define the list
        With ws
            Set rCombo = .Range("C3:C15")
        End With
        'populate the combobox using the List Property
        Me.ComboBox1.List = rCombo.Value
            
        Sheets("Ark2").Select
        Dim mg As Worksheet
        Dim mgCombo As Range
    
        'set a variable to the sheet with the list
        Set mg = Sheet2
        'define the list
        With mg
            Set mgCombo = .Range("M3:M12")
        End With
        'populate the combobox using the List Property
        Me.ComboBox3.List = mgCombo.Value
        
        Sheets("Ark2").Select
        Dim mgg As Worksheet
        Dim mggCombo As Range
    
        'set a variable to the sheet with the list
        Set mgg = Sheet2
        'define the list
        With mgg
            Set mggCombo = .Range("N3:N10")
        End With
        'populate the combobox using the List Property
        Me.ComboBox2.List = mggCombo.Value
        
        'Bilagsnr. default
        Sheets("Konteringsliste").Select
        Dim bilagsnrfelt As Range
        Set bilagsnrfelt = Range("b6:b95")
        forrigebilagsnr = Application.Max(bilagsnrfelt)
        Bilagsnummer = forrigebilagsnr + 1
        
        Me.TextBox3.Text = Bilagsnummer
        
        'Sett case   til ComboBox1. Text
    Select Case Me.ComboBox1.Text
    '"Case" = Sjekker hva som står i ComboBox 1 for så å postere dette!
    
    Case Me.ComboBox1
    
        
        'Søke
        Cells.Find(What:=Me.ComboBox1, After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
            
        Tekst = ActiveCell.Text
        Selection.Offset(0, 1).Select
        Debet = ActiveCell.Value
        Selection.Offset(0, 1).Select
        DebetKonto = ActiveCell.Value
        Selection.Offset(0, 1).Select
        DebetMva = ActiveCell.Value
        Selection.Offset(0, 1).Select
        Kredit = ActiveCell.Value
        Selection.Offset(0, 1).Select
        KreditKonto = ActiveCell.Value
        Selection.Offset(0, 1).Select
        KreditMva = ActiveCell.Value
        
        End Select
        
        'Sett data hentet som default i tekstboksene
        Me.TextBox7.Text = Tekst
        Me.TextBox8.Value = Debet
        Me.TextBox9.Value = Kredit
        Me.TextBox10.Text = DebetKonto
        Me.TextBox13.Text = KreditKonto
        Me.TextBox11.Value = DebetMva
        Me.TextBox12.Value = KreditMva
        
           
        
    End Sub
    Hello.

    I get this error message when I try to run it "runtime error 91 object variable or With block variable not set"
    It is part of a UserForm.

    This is the part that creates problems.

    Select Case Me.ComboBox1.Text
    '"Case" = Sjekker hva som står i ComboBox 1 for så å postere dette!
    
    Case Me.ComboBox1
    
        
        'Søke
        Cells.Find(What:=Me.ComboBox1, After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
            
        Tekst = ActiveCell.Text
        Selection.Offset(0, 1).Select
        Debet = ActiveCell.Value
        Selection.Offset(0, 1).Select
        DebetKonto = ActiveCell.Value
        Selection.Offset(0, 1).Select
        DebetMva = ActiveCell.Value
        Selection.Offset(0, 1).Select
        Kredit = ActiveCell.Value
        Selection.Offset(0, 1).Select
        KreditKonto = ActiveCell.Value
        Selection.Offset(0, 1).Select
        KreditMva = ActiveCell.Value
        
        End Select
        
        'Sett data hentet som default i tekstboksene
        Me.TextBox7.Text = Tekst
        Me.TextBox8.Value = Debet
        Me.TextBox9.Value = Kredit
        Me.TextBox10.Text = DebetKonto
        Me.TextBox13.Text = KreditKonto
        Me.TextBox11.Value = DebetMva
        Me.TextBox12.Value = KreditMva
    It is something that is at the Norwegian. Because I am a Norwegian

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: runtime error 91 object variable or With block variable not set

    The message means the value has not been found.

    On error resume next
    
    Select Case Me.ComboBox1.Text
    Case "criterion1"
    '  ----
    Case "criterion2"
      With sheets(1).Cells.Find(ComboBox1.text, , xlFormulas, lPart), 
        for j=0 to 6
          Me("TextBox" & j+7).Text =.offset(,j).value
        next
      end with
    End Select
    Besides, this should suffice:

    Private Sub UserForm_Initialize()
      for j=1 to 3
        Me("Combobox" & j ).list= sheets("Ark2").range(choose(j,"C3:C15","N3:N10","M3:M12")).value
      next    
         
      TextBox3.Text = application.max(Sheets("Konteringsliste").Range("b6:b95"))+1
    
      Select Case Me.ComboBox1.Text
      Case "criterion1"
    '     ----
      Case "criterion2"
        With sheets(1).Cells.Find(ComboBox1.text, , xlFormulas, lPart), 
          for j=0 to 6
            Me("TextBox" & j+7).Text =.offset(,j).value
          next
        end with
      End Select     
    End Sub
    Last edited by snb; 02-14-2011 at 01:36 PM.



+ Reply to Thread

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