Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Range("C3") Is Nothing Then Exit Sub
On Error GoTo 0
If Not Intersect(Target, Range("C3")) Is Nothing Then
Range("F7").Select
ActiveCell.FormulaR1C1 = _
"=SUMPRODUCT((Month=R2C3)*(Location=R3C3)*(Process=RC4)*(Skill_Set=RC1)*(Source_Type<>R2C4)*(Final_Status=R3C4))"
Range("G7").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(SUMPRODUCT((Month=R2C3)*(Location=R3C3)*(Process=RC4)*(Skill_Set=RC1)*(Source_Type<>R2C4)*(Final_Status=R3C4)*(Annual_CTC))/RC[-1]),"""",((SUMPRODUCT((Month=R2C3)*(Location=R3C3)*(Process=RC4)*(Skill_Set=RC1)*(Source_Type<>R2C4)*(Final_Status=R3C4)*(Annual_CTC))/RC[-1])))"
Range("H7").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(SUMPRODUCT((Month=R2C3)*(Location=R3C3)*(Process=RC4)*(Skill_Set=RC1)*(Source_Type<>R2C4)*(Final_Status=R3C4)*(Targeted_Budget))/RC[-2]),"""",((SUMPRODUCT((Month=R2C3)*(Location=R3C3)*(Process=RC4)*(Skill_Set=RC1)*(Source_Type<>R2C4)*(Final_Status=R3C4)*(Targeted_Budget))/RC[-2])))"
Range("I7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]="""","""",IF(ISERROR((RC[-1]-RC[-2])/RC[-1]),0,(RC[-1]-RC[-2])/RC[-1]))"
Range("J7").Select
ActiveCell.FormulaR1C1 = "=IF(ISERROR(RC[-4]*RC[-3]),"""",((RC[-4]*RC[-3])))"
Range("K7").Select
ActiveCell.FormulaR1C1 = "=IF(ISERROR(RC[-5]*RC[-3]),"""",((RC[-5]*RC[-3])))"
Range("L7").Select
ActiveCell.FormulaR1C1 = "=IF(ISERROR(RC[-1]-RC[-2]),"""",((RC[-1]-RC[-2])))"
Range("F7:L7").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Range("F7:L50").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("F7:G7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("F7:L50").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("B7:L50").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("B2:L6").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End If
Range("C2:C3").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 4
End With
With Selection.Interior
.ColorIndex = 5
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("A1").Select
End Sub
This macro has been recorded.
I want to put this in loop.
Let me tell how it works first.
Intially it puts the formula from cell F7 to L7
and then it copys the F7toL7 formulas and paste it till row 50.and does a pastes special value.
I want this to be in Loop.First it will put he formula in F7 if D7 in not blank.and do a paste special value.and this should happen for all the formulas till L column.
Please help