title: How to fix Runtime Error "91" in Excel
body: <p>I have created a userform to enter data into worksheets for me. I am trying to code it where it will put the information into a selected worksheet. I have a combobox where I can select the sheet I want it to put the info in. I am trying to set the variable ws to the combobox value and I get a runtime error '91' and it says "object variable or with block not set". The code I am having problems with is below.</p>
  
  <pre><code>Private Sub bttn_Submit_Click()
  Dim iRow As Long
  Dim ws As Worksheet
  
  'set the variable for the worksheet
  ws = ComboBox1.Value
  
  'find first empty row in database
  iRow = Columns("A").Find("*", SearchOrder:=xlRows, _
      SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
  
  
  
  'check for a date
  If Trim(Me.txt_Date.Value) = "" Then
    Me.txt_Date.SetFocus
    MsgBox "Please enter a Date"
    Exit Sub
  End If
  
  'copy the data to the database
  'use protect and unprotect lines,
  '     with your password
  '     if worksheet is protected
  With ws
  '  .Unprotect Password:="password"
    .Cells(iRow, 1).Value = Me.txt_Date.Value
    .Cells(iRow, 2).Value = Me.txt_Invoice.Value
    .Cells(iRow, 3).Value = Me.txt_Mileage.Value
    .Cells(iRow, 5).Value = Me.CheckBox_Oil_Filter
    .Cells(iRow, 7).Value = Me.CheckBox_Air_Filter
    .Cells(iRow, 9).Value = Me.CheckBox_Primary_Fuel_Filter
    .Cells(iRow, 11).Value = Me.CheckBox_Secondary_Fuel_Filter
    .Cells(iRow, 13).Value = Me.CheckBox_Transmission_Filter
    .Cells(iRow, 15).Value = Me.CheckBox_Transmission_Service
    .Cells(iRow, 17).Value = Me.CheckBox_Wiper_Blades
    .Cells(iRow, 19).Value = Me.CheckBox_Rotation_Rotated
    .Cells(iRow, 21).Value = Me.CheckBox_New_Tires
    .Cells(iRow, 23).Value = Me.CheckBox_Differential_Service
    .Cells(iRow, 25).Value = Me.CheckBox_Battery_Replacement
    .Cells(iRow, 27).Value = Me.CheckBox_Belts
    .Cells(iRow, 29).Value = Me.CheckBox_Lubricate_Chassis
    .Cells(iRow, 30).Value = Me.CheckBox_Brake_Fluid
    .Cells(iRow, 31).Value = Me.CheckBox_Coolant_Check
    .Cells(iRow, 32).Value = Me.CheckBox_Power_Steering_Check
    .Cells(iRow, 33).Value = Me.CheckBox_A_Transmission_Check
    .Cells(iRow, 34).Value = Me.CheckBox_Washer_Fluid_Check
  
  
  '  .Protect Password:="password"
  End With
  
  'clear the data
  Me.txt_Date.Value = ""
  Me.txt_Invoice.Value = ""
  Me.txt_Mileage.Value = ""
  Me.txt_Date.SetFocus
  
  End Sub
  </code></pre>