title: Excel VBA - Loop through workbook and label a cell with each sheet's name
body: <p>I'm trying to write code where you click one cell on the active sheet and it loops through the rest of the sheets and labels that cell with each sheet's tab name. </p>
  
  <p>The code below works fine if:</p>
  
  <pre><code>For Each Ws In Worksheets
          wb.Worksheets(1).Range("A1").FormulaR1C1 = ActiveSheet.Name
  Next
  </code></pre>
  
  <p>but as soon as I call the input box variable, the code errors out. How should I correctly implement the input box into this code?</p>
  
  <pre><code>Public Sub FastWB(Optional ByVal opt As Boolean = True)
      With Application
          .Calculation = IIf(opt, xlCalculationManual, xlCalculationAutomatic)
          .DisplayAlerts = Not opt
          .DisplayStatusBar = Not opt
          .EnableAnimations = Not opt
          .EnableEvents = Not opt
          .ScreenUpdating = Not opt
      End With
      FastWS , opt
  End Sub
  
  Public Sub FastWS(Optional ByVal Ws As Worksheet = Nothing, _
                    Optional ByVal opt As Boolean = True)
      If Ws Is Nothing Then
          For Each Ws In Application.ActiveWorkbook.Sheets
              EnableWS Ws, opt
          Next
      Else
          EnableWS Ws, opt
      End If
  End Sub
  
  Private Sub EnableWS(ByVal Ws As Worksheet, ByVal opt As Boolean)
      With Ws
          .DisplayPageBreaks = False
          .EnableCalculation = Not opt
          .EnableFormatConditionsCalculation = Not opt
          .EnablePivotTable = Not opt
      End With
  End Sub
  
  Sub SheetLabel()
  
  Dim Ws As Worksheet
  Dim wb As Workbook
  Dim t As Double
  Dim cellVal As Range
  Set wb = Application.ActiveWorkbook
  
  'Optimize Macro Speed
  FastWB True: t = Timer
  
  
  Set cellVal = Application.InputBox("Click cell to add label to", Type:=8)
  
  
  For Each Ws In Worksheets
          wb.Worksheets(1).Range("cellVal").FormulaR1C1 = ActiveSheet.Name
  Next
  
  FastWB False: MsgBox CStr(Round(Timer - t, 2)) &amp; "s" 'Display duration of task
  
  End Sub
  </code></pre>