PDA

View Full Version : Solved: repopulate formulas



Cartwheels
09-22-2009, 01:41 PM
I need to add on to my macro to repopulate the formula in range E9-E50. This macro is used for payroll. Users need to change the rate of pay on column E, then I have to manually fix the formula. I am hoping someone can help me make it a little more automatic. I attached a sample of the workbook.

Sub Clear()
'
' Clear Macro
'
'
'

'Clear
Dim i As Long

For i = 2 To Worksheets.Count

With Worksheets(i)
.Unprotect
.Range("A5") = "999999"
.Range("A9:d50").ClearContents
.Range("E6:K6") = "1"
'I need to re-populate the formula in range("E9:E50") here
.Range("E1:iv50").Interior.ColorIndex = 15
.Protect
.Range("A9") = "1"
End With
Next i
Sheets("Entry 1").Select
Range("A5").Select

End Sub

Bob Phillips
09-22-2009, 02:16 PM
Sub Clear()
'
' Clear Macro
' Macro recorded 11/4/2008 by Your User Name
'

'
Worksheets("Info").Range("H4:H10").Value = 1

'Clear
Dim i As Long

For i = 2 To Worksheets.Count

With Worksheets(i)

.Unprotect
.Range("A5") = "999999"
.Range("A9:D50").ClearContents
.Range("E6:K6") = 1
.Range("E1:IV50").Interior.ColorIndex = 15
.Range("E9:E50").Formula = "=IF(AW9=10,D$5,IF(AW9<=13,IF(K$1=""I""," & _
"IF(OR($BF9<1300,$BF9=8250,$BF9=8266,G9=1),BA9+AZ9+AY9," & _
"IF(BF9=1310,AX9,IF(AND(AY9=0,AZ9=0),"""",D$5+AZ9+AY9)))," & _
"IF(AND(AY9=0,AZ9=0),"""",D$5+AZ9+AY9)),""""))"
.Protect
.Range("A9") = 1
End With
Next i

Sheets("Entry 1").Select
Range("A5").Select


End Sub

Cartwheels
09-22-2009, 02:36 PM
Thank you, I tried it and it appears to work correctly. I tried to write something similar myself, but did not have it correct and even then I wasn't sure it would fill down correctly.

Thanks again!!!

Cartwheels
09-22-2009, 02:49 PM
Wierd how you have to add more quotes to the stuff (text) that was already in quotes.

Bob Phillips
09-22-2009, 02:53 PM
Not really, if you didn't, it would assume the first quotes was closing the string. So you escape the quotes with more quotes.