ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Value NOT placed in 2 sheets, but in ALL others (https://www.excelbanter.com/excel-programming/404739-value-not-placed-2-sheets-but-all-others.html)

Corey

Value NOT placed in 2 sheets, but in ALL others
 
Sub Workbook_Info()
On Error Resume Next
With Sheets("1:50")
' If sheet is NOT sheet1 or sheet3 then
..Select
ActiveSheet.Unprotect
Range("R59").Select
ActiveCell.FormulaR1C1 = "=MAX('Page 1:" & Worksheets(Worksheets.Count).Name & "'!R[0]C[-8])"
ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
End With
End Sub

The above code places the MAX value in cell R59 in ALL sheets in my workbook.
But i have discovered that i DO NOT want it to be placed in 2 sheets of the workbook.
Sheet1 and Sheet3.

How can skip sheet1 and 3 so they are not included in the code above?

Corey....



Nigel[_2_]

Value NOT placed in 2 sheets, but in ALL others
 
You need to loop through each sheet bypassing the ones you do not wish to
add the formula.

Dim X as Long
For X = 2 to 50
With Worksheets(X)
If .Name < "Sheet3" then
.Unprotect
.Range("R59").FormulaR1C1 = "=MAX('Page 1:" &
Worksheets(Worksheets.Count).Name & "'!R[0]C[-8])"
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
End If
Next X

--

Regards,
Nigel




"Corey" wrote in message
...
Sub Workbook_Info()
On Error Resume Next
With Sheets("1:50")
' If sheet is NOT sheet1 or sheet3 then
.Select
ActiveSheet.Unprotect
Range("R59").Select
ActiveCell.FormulaR1C1 = "=MAX('Page 1:" &
Worksheets(Worksheets.Count).Name & "'!R[0]C[-8])"
ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
End With
End Sub

The above code places the MAX value in cell R59 in ALL sheets in my
workbook.
But i have discovered that i DO NOT want it to be placed in 2 sheets of
the workbook.
Sheet1 and Sheet3.

How can skip sheet1 and 3 so they are not included in the code above?

Corey....





All times are GMT +1. The time now is 03:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com