title: Macro give Error 91 second time when other macro runs and closes an userform
body: <p>I have two macros. One macro is used for re-sizing the excel sheet for different monitors by minimizing ribbons and zoom in feature. Another macro where i can write some problems in a particular excel sheet table using the text input from the user. This macro activates a userform where the user can enter the data.
  1st macro runs perfectly in all the excel sheet as expected. If i run second macro one time and tried to run the 1st macro  again. It always give object variable not set error on 1st macro in the line <strong><em>" MaxCol  = Rows(1)....".</em></strong> I have to close and reopen it in order to run the 1st macro again. </p>
  
  <p>I have no idea why this is arising. I have properly closed (Unloaded) the object of Userform if user presses ok or cancel.</p>
  
  <p>Below is the code for first macro.</p>
  
  <pre><code>Sub OptimalSize()
  
  Dim SheetName As String
  Dim MaxCol As Long
  
  SheetName = ""
  MaxCol = 0
  
  CommandBars.ExecuteMso "MinimizeRibbon"
  
  Application.WindowState = xlMaximized
  
  SheetName = ActiveSheet.Name
  
  MaxCol = Rows(1).Find(1, SearchOrder:=xlByColumns,    SearchDirection:=xlNext, MatchCase:=False).Column
  
  Sheets(SheetName).Select
  ActiveSheet.Range("A1", Cells(1, MaxCol)).Select
  ActiveWindow.Zoom = True
  Application.Goto Reference:=Worksheets(SheetName).Range("A1"), Scroll:=True  
  End Sub
  </code></pre>
  
  <p>The second macro after some computation which calls the userform</p>
  
  <pre><code>Sub ProblemBoard()
  
  ' code here to find out empty space in a table!!'
  
   Userform1.Show 
  End sub
  </code></pre>
  
  <p>The userform code below</p>
  
  <pre><code>Sub CommandButton1_Click()
  
  Application.ScreenUpdating = False
  
  Worksheets("Problem Board").Cells(z, 2).Value = TextBox1.Text
  Worksheets("Problem Board").Cells(z, 5).Value = TextBox2.Text
  
  Unload Me
  Sheets(ActWS).Select
  Application.ScreenUpdating = True
  
  End Sub
  
  Private Sub CommandButton2_Click()
  
    Unload Me
    Sheets(ActWS).Select
    Application.ScreenUpdating = True
  End Sub
  
  Private Sub UserForm_Initialize()
  
  
  Dim lng As Long
  
  'ActWS = ActiveSheet.Name
  
  lng  = Sheets("Listen").Range("A65536").End(xlUp).Row
  Me.ComboBox2.List = Sheets("Listen").Range("A2:A" &amp; lng ).Value
  TextBox1 = ""
  TextBox2 = ""
  
  End Sub
  </code></pre>