title: Excel VBA - Run-time error 438 - When pulling a value using a For Loop
body: <p>I am trying to pull a string from a range of cells in a Sheet to test in an If statement to determine which action to take. Debug highlights the below line as the cause of the error:</p>
  <pre><code>testValue = Sheets(&quot;Issue Reference&quot;).testRange.Value
  </code></pre>
  <p>but I can't figure out why that is a problem, maybe something with the .Value property? Any ideas? Entire code below:</p>
  <pre><code>Private Sub SubGroupList_Click()
  Dim selection As String
  Dim rng As Range
  Dim testRange As Range
  Dim i As Integer
  Dim testValue As String
  
  selection = SubGroupList.Value
  
  If failedComponentTrack = 1 Then
      Set rng = Range(&quot;C3:C10&quot;)
  
  ElseIf failedComponentTrack = 2 Then
      Set rng = Range(&quot;E3:E10&quot;)
  
  ElseIf failedComponentTrack = 3 Then
      Set rng = Range(&quot;G3:G10&quot;)
  
  Else
  
  End If
  
  i = 1
  For Each testRange In rng
      testValue = Sheets(&quot;Issue Reference&quot;).testRange.Value
      If selection = testValue Then
          Sheets(&quot;DataStore&quot;).Cells(LB, 27).Value = selection
          failedComponentTrack = i
      End If
      i = i + 1
  Next testRange
  End Sub
  </code></pre>