call code for all sheets
sh is your worksheet object, but call test needs to know which sheet. Try this
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.Activate
with sh
call test(sh)
end with
Next sh
Sub Test(sh as worksheet)
msgbox sh.name
end sub
--
HTH...
Jim Thomlinson
"rwnelson" wrote:
Through browsing this group, I have been able to apply code to all the
sheets in my workbook with the following test code.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$E$2" Then Exit Sub
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.Activate
sh.Range("G2") = "test worked"
Next
End Sub
'--------------------------------------------------------------------------------------------
Is there any way to call a sub to all worksheets. I've tried
replaceing the SH.RANGE line with CALL TEST and it did not apply it to
all sheets. I've tried using WITH statements as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$E$2" Then Exit Sub
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.Activate
with sh
call test
end with
Next
End Sub
This did not work either. Any suggestions?
|