sjv5150
04-18-2008, 09:38 AM
I have a code that loops through 240 cells to input the following formulas from a worksheet called "Performance." The looks at the values of the cells in the "Performance" worksheet and flags them (returns a value of 1 or 0) based on the 4 different scenarios. I am running into a problem with the speed of the macro. It is super slow. It actually is pasting the formula into each indidvidual cell 240 times (takes about 45 seconds). Even with the ScreenUpdating set to False, it still takes a long time. I can't copy/paste the formulas either because Excel can't recognize the pattern. There must be a more efficient way of performing this. Any help will be much appreciated.
For Counter = 1 To 60
g = ActiveCell.Row
h = ActiveCell.Column
i = ColNo2ColRef(h) ' From Function
h = h + 1
j = ColNo2ColRef(h) ' From Function
ws2.Activate
Selection.formula = "=IF(Performance!" & i & g & ">0,IF (Performance!" & j & g & ">0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & ">0,IF(Performance!" & j & g & "<=0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & "<=0,IF(Performance!" & j & g & "<=0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & "<0,IF(Performance!" & j & g & ">=0,1,0),0)"
Selection.Offset(0, 1).Activate
ws1.Activate
Selection.Offset(0, 2).Activate
Next
For Counter = 1 To 60
g = ActiveCell.Row
h = ActiveCell.Column
i = ColNo2ColRef(h) ' From Function
h = h + 1
j = ColNo2ColRef(h) ' From Function
ws2.Activate
Selection.formula = "=IF(Performance!" & i & g & ">0,IF (Performance!" & j & g & ">0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & ">0,IF(Performance!" & j & g & "<=0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & "<=0,IF(Performance!" & j & g & "<=0,1,0),0)"
Selection.Offset(0, 1).Activate
Selection.formula = "=IF(Performance!" & i & g & "<0,IF(Performance!" & j & g & ">=0,1,0),0)"
Selection.Offset(0, 1).Activate
ws1.Activate
Selection.Offset(0, 2).Activate
Next