title: Activate worksheet using excel VBA
body: <p>I have a file "Workbook A" in a folder. An updated version is sent to me every fortnight. I want to open this workbook from another workbook, "Workbook B" and at the same time delete blank rows in "Workbook A". </p>
  
  <p>The opening and deleting operations will occur through the use of a macro. </p>
  
  <p>This is my code thus far.</p>
  
  <pre><code>Sub RemoveEmptyRows()
      ' this macro will remove all rows that contain no data
      ' ive named 2 variables of data type string
      Dim file_name  As String
      Dim sheet_name As String
  
      file_name = "C:\Users\Desktop\Workstation_A\Workbook_A.xlsm"
      'Change to whatever file i want
      sheet_name = "Worksheet_A"   'Change to whatever sheet i want
  
      ' variables "i" and "LastRow" are needed for the for loop
      Dim i As Long
      Dim LastRow As Long
  
      ' we set wb as a new work book since we have to open it
      Dim wb As New Workbook
  
      ' To open and activate workbook
      ' it opens and activates the workbook_A and activates the worksheet_A
      Set wb = Application.Workbooks.Open(file_name)
      wb.Sheets(sheet_name).Activate
  
      ' (xlCellTypeLastCell).Row is used to find the last cell of the last row
      ' i have also turned off screen updating
      LastRow = wb.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
      Application.ScreenUpdating = False
  
      ' here i am using a step
      ' the step is negative
      ' therefore i start from the last row and go to the 1st in steps of 1
      For i = LastRow To 1 Step -1
      ' Count A - Counts the number of cells that are not empty and the
      ' values within the list of arguments (wb..ActiveSheet.Rows(i))
      ' Afterwards deleting the rows that are totally blank
          If WorksheetFunction.CountA(wb.ActiveSheet.Rows(i)) = 0 Then
              wb.ActiveSheet.Rows(i).EntireRow.Delete
          End If
      Next i
  
      ' used to update screen
      Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>The work sheet name contains <code>Worksheet_A</code> as part of its name followed by a  date. For example <code>Worksheet_A 11-2-15</code>.</p>
  
  <p>In my code, I have assigned the variable <code>sheet_name</code> to <code>Worksheet_A</code></p>
  
  <pre><code>sheet_name = "Worksheet_A" 
  </code></pre>
  
  <p>and further down  I have used</p>
  
  <pre><code>.Sheets(sheet_name).Activate
  </code></pre>
  
  <p>to activate the worksheet. I feel there is an issue with below line:</p>
  
  <pre><code>sheet_name = "Worksheet_A"
  </code></pre>
  
  <p>since <code>sheet_name</code> is not exactly <strong>Worksheet_A</strong> it only contains <strong>Worksheet_A</strong> as part of its name.</p>
  
  <p>This is causing a problem.The workbook A opens but the deleting of blank rows does not occur.<br> Further more an error message is displayed.</p>
  
  <blockquote>
    <p>Run Time Error 9: Subscript out of Range.</p>
  </blockquote>
  
  <p>How do I modify my code so that the worksheet gets activated and the macro operations are performed?</p>