ziad alsayed
Well-known Member
- Joined
- Jul 17, 2010
- Messages
- 665
dear all
the below code is workin fine. i just need to reduce it
Appreciate any help
thanks in advance
the below code is workin fine. i just need to reduce it
Appreciate any help
Code:
Sub try()
Dim wb As Workbook
Set wb = ActiveWorkbook
Worksheets("Detailed Report").Select
If Cells(1, 1) = "DecemberP" Then
Worksheets("2011").Select
Cells(5, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(5, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(5, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(5, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(5, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(5, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "January" Then
Worksheets("2011").Select
Cells(6, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(6, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(6, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(6, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(6, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(6, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "February" Then
Worksheets("2011").Select
Cells(7, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(7, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(7, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(7, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(7, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(7, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "March" Then
Worksheets("2011").Select
Cells(8, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(8, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(8, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(8, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(8, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(8, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "April" Then
Worksheets("2011").Select
Cells(9, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(9, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(9, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(9, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(9, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(9, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "May" Then
Worksheets("2011").Select
Cells(10, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(10, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(10, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(10, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(10, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(10, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "June" Then
Worksheets("2011").Select
Cells(11, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(11, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(11, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(11, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(11, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(11, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "July" Then
Worksheets("2011").Select
Cells(12, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(12, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(12, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(12, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(12, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(12, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "August" Then
Worksheets("2011").Select
Cells(13, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(13, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(13, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(13, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(13, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(13, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "September" Then
Worksheets("2011").Select
Cells(14, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(14, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(14, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(14, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(14, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(14, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "October" Then
Worksheets("2011").Select
Cells(15, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(15, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(15, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(15, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(15, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(15, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "November" Then
Worksheets("2011").Select
Cells(16, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(16, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(16, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(16, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(16, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(16, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
ElseIf Cells(1, 1) = "December" Then
Worksheets("2011").Select
Cells(17, 24).FormulaR1C1 = "=COUNTIFS(Total!C[-15],Expatriate,Total!C[-18],PH)"
Cells(17, 25).FormulaR1C1 = "=COUNTIFS(Total!C[-16],Expatriate,Total!C[-19],Apapa)"
Cells(17, 26).FormulaR1C1 = "=COUNTIFS(Total!C[-17],Expatriate,Total!C[-20],VI)"
Cells(17, 27).FormulaR1C1 = "=COUNTIFS(Total!C[-18],Expatriate,Total!C[-21],Kano)"
Cells(17, 28).FormulaR1C1 = "=COUNTIFS(Total!C[-19],Expatriate,Total!C[-22],Ikeja)"
Cells(17, 29).FormulaR1C1 = "=COUNTIFS(Total!C[-20],Expatriate,Total!C[-23],Assembly)"
Worksheets("Detailed Report").Select
End If
End Sub
thanks in advance