AnswerSeeker
03-29-2012, 12:18 AM
Hello,
I want that my procedures (inserting 2 additional lines at the top in color) are done for every worksheet. But rather than it is only working the activesheet (in my case I have 3 worksheets, and my code insert 6 lines in the activesheet and do nothing in the other worksheets). What is my mistake?
Sub Kombi()
Application.ScreenUpdating = False
For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
numbers = ActiveSheet.UsedRange.Columns.Count
For i = 1 To 2
ActiveSheet.Rows(i).Insert
Next i
For col = 1 To numbers
Cells(1, col).Interior.Color = vbGreen
Cells(2, col).Interior.Color = vbGreen
Next col
End With
Next wkSht
Application.ScreenUpdating = True
End Sub
I want that my procedures (inserting 2 additional lines at the top in color) are done for every worksheet. But rather than it is only working the activesheet (in my case I have 3 worksheets, and my code insert 6 lines in the activesheet and do nothing in the other worksheets). What is my mistake?
Sub Kombi()
Application.ScreenUpdating = False
For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
numbers = ActiveSheet.UsedRange.Columns.Count
For i = 1 To 2
ActiveSheet.Rows(i).Insert
Next i
For col = 1 To numbers
Cells(1, col).Interior.Color = vbGreen
Cells(2, col).Interior.Color = vbGreen
Next col
End With
Next wkSht
Application.ScreenUpdating = True
End Sub