title: Conditional Inserting using VBA
body: <p>I was trying to insert a row just below another row base on some condition. Now this code will loop through many sheets. It work fine for 1 sheet, but when it tries to perform the same function for next sheet, it showing error. Can anybody help me to solve the problem. The code I was using is given below:</p>
  
  <pre><code>Sub test()
  Dim a As Worksheet
  Dim lngRow As Long
  Dim s As String
  Dim z As Variant
  s = "Sheet1,Sheet2"
  z = VBA.Split(s, ",")
  For Each i In z
  Set a = Sheets(i)
  For lngRow = a.UsedRange.Rows.Count To 1 Step -1
  If UCase$(a.Cells(lngRow, 2).Value) = "R" Then
  a.Range("A" &amp; CStr(lngRow + 1)).Select
  Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
  End If
  Next lngRow
  Next i
  End Sub
  </code></pre>
  
  <p>The error is coming in this row:</p>
  
  <pre><code>a.Range("A" &amp; CStr(lngRow + 1)).Select
  </code></pre>