Greetings,
I'm trying to insert two rows in a subset of worksheets in a workbook by defining a range in a worksheet and loop through the worksheets in that range, but the code will only run on the active worksheet.
Sub StatePIPData()
Dim sheet_name As Range
For Each sheet_name In Sheets("WS").Range("A:A")
If sheet_name.Value = "" Then
Exit For
Else
'Insert 2 rows for 2011 and 2012's data
Range("A14").EntireRow.Insert
Cells(14, 1) = Cells(15, 1) + 1
Range("A14").EntireRow.Insert
Cells(14, 1) = Cells(15, 1) + 1
End If
Next sheet_name
End Sub
Any thoughts on how I could get this loop to work?
Thank you very much,
I'm trying to insert two rows in a subset of worksheets in a workbook by defining a range in a worksheet and loop through the worksheets in that range, but the code will only run on the active worksheet.
Sub StatePIPData()
Dim sheet_name As Range
For Each sheet_name In Sheets("WS").Range("A:A")
If sheet_name.Value = "" Then
Exit For
Else
'Insert 2 rows for 2011 and 2012's data
Range("A14").EntireRow.Insert
Cells(14, 1) = Cells(15, 1) + 1
Range("A14").EntireRow.Insert
Cells(14, 1) = Cells(15, 1) + 1
End If
Next sheet_name
End Sub
Any thoughts on how I could get this loop to work?
Thank you very much,