View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jan Karel Pieterse Jan Karel Pieterse is offline
external usenet poster
 
Posts: 535
Default Update formula in Multi sheets

Hi Newbie,

Sub UpdateDesc()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect
Rows("5:5").RowHeight = 18.75
Range("G5").Select
ActiveCell.Formula =

"=IF(VLOOKUP(B4,Contracts!$A$1:$E$168,5,FALSE)=0," ",VLOOKUP(B4,Contract
s!$A$1:$E$168,5,FALSE))"
wks.EnableSelection = xlUnlockedCells
wks.Protect
End If
Next

End Sub


Your code references the active worksheet, precede every range object
with the worksheet object:

Sub UpdateDesc()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect
wks.Rows("5:5").RowHeight = 18.75
wks.Range("G5").Formula =
"=IF(VLOOKUP(B4,Contracts!$A$1:$E$168,5,FALSE)=0," ",VLOOKUP(B4,Contract
s!$A$1:$E$168,5,FALSE))"
wks.EnableSelection = xlUnlockedCells
wks.Protect
End If
Next

End Sub

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com