宏运行并循环遍历所有工作表,但第一个工作表

时间:2017-02-26 06:55:33

标签: excel vba excel-vba

我有下面的宏。我正在寻找两件事:

1)更好的写作方式(我似乎无法使其适用于范围或任何其他方式)

2)让它循环遍历除第一个工作表之外的所有工作表(未知数量,未知名称)。

Sub Macro1()
'
' Macro1 Macro
'
    Range("C3").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C"
    Range("C4").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-2]C"
    Range("C5").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-3]C"
    Range("C6").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-4]C"
    Range("C7").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-5]C"
    Range("C8").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-6]C"
    Range("C9").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-7]C"
    Range("C10").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-8]C"
    Range("C11").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-9]C"
    Range("C12").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-10]C"
    Range("C13").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-11]C"
    Range("C14").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-12]C"
    Range("C15").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-13]C"
    Range("C16").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-14]C"
    Range("C17").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-15]C"
    Range("C18").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-16]C"
    Range("C19").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-17]C"
    Range("C20").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-18]C"
    Range("C21").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-19]C"
    Range("C22").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-20]C"
    Range("C23").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-21]C"
    Range("C24").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-22]C"
    Range("C25").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-23]C"
    Range("C26").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*R[-24]C"
    Range("D3").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-1]C"
    Range("D4").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-2]C"
    Range("D5").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-3]C"
    Range("D6").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-4]C"
    Range("D7").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-5]C"
    Range("D8").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-6]C"
    Range("D9").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-7]C"
    Range("D10").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-8]C"
    Range("D11").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-9]C"
    Range("D12").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-10]C"
    Range("D13").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-11]C"
    Range("D14").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-12]C"
    Range("D15").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-13]C"
    Range("D16").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-14]C"
    Range("D17").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-15]C"
    Range("D18").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-16]C"
    Range("D19").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-17]C"
    Range("D20").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-18]C"
    Range("D21").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-19]C"
    Range("D22").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-20]C"
    Range("D23").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-21]C"
    Range("D24").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-22]C"
    Range("D25").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-23]C"
    Range("D26").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*R[-24]C"
    Range("E3").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C"
    Range("E4").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-2]C"
    Range("E5").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-3]C"
    Range("E6").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-4]C"
    Range("E7").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-5]C"
    Range("E8").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-6]C"
    Range("E9").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-7]C"
    Range("E10").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-8]C"
    Range("E11").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-9]C"
    Range("E12").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-10]C"
    Range("E13").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-11]C"
    Range("E14").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-12]C"
    Range("E15").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-13]C"
    Range("E16").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-14]C"
    Range("E17").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-15]C"
    Range("E18").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-16]C"
    Range("E19").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-17]C"
    Range("E20").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-18]C"
    Range("E21").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-19]C"
    Range("E22").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-20]C"
    Range("E23").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-21]C"
    Range("E24").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-22]C"
    Range("E25").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-23]C"
    Range("E26").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]*R[-24]C"
    Range("F3").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-1]C"
    Range("F4").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-2]C"
    Range("F5").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-3]C"
    Range("F6").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-4]C"
    Range("F7").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-5]C"
    Range("F8").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-6]C"
    Range("F9").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-7]C"
    Range("F10").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-8]C"
    Range("F11").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-9]C"
    Range("F12").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-10]C"
    Range("F13").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-11]C"
    Range("F14").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-12]C"
    Range("F15").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-13]C"
    Range("F16").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-14]C"
    Range("F17").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-15]C"
    Range("F18").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-16]C"
    Range("F19").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-17]C"
    Range("F20").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-18]C"
    Range("F21").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-19]C"
    Range("F22").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-20]C"
    Range("F23").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-21]C"
    Range("F24").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-22]C"
    Range("F25").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-23]C"
    Range("F26").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]*R[-24]C"
    Range("G3").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-1]C"
    Range("G4").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-2]C"
    Range("G5").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-3]C"
    Range("G6").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-4]C"
    Range("G7").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-5]C"
    Range("G8").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-6]C"
    Range("G9").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-7]C"
    Range("G10").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-8]C"
    Range("G11").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-9]C"
    Range("G12").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-10]C"
    Range("G13").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-11]C"
    Range("G14").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-12]C"
    Range("G15").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-13]C"
    Range("G16").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-14]C"
    Range("G17").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-15]C"
    Range("G18").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-16]C"
    Range("G19").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-17]C"
    Range("G20").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-18]C"
    Range("G21").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-19]C"
    Range("G22").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-20]C"
    Range("G23").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-21]C"
    Range("G24").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-22]C"
    Range("G25").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-23]C"
    Range("G26").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]*R[-24]C"
    Range("H3").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-1]C"
    Range("H4").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-2]C"
    Range("H5").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-3]C"
    Range("H6").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-4]C"
    Range("H7").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-5]C"
    Range("H8").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-6]C"
    Range("H9").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-7]C"
    Range("H10").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-8]C"
    Range("H11").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-9]C"
    Range("H12").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-10]C"
    Range("H13").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-11]C"
    Range("H14").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-12]C"
    Range("H15").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-13]C"
    Range("H16").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-14]C"
    Range("H17").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-15]C"
    Range("H18").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-16]C"
    Range("H19").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-17]C"
    Range("H20").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-18]C"
    Range("H21").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-19]C"
    Range("H22").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-20]C"
    Range("H23").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-21]C"
    Range("H24").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-22]C"
    Range("H25").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-23]C"
    Range("H26").Select
    ActiveCell.FormulaR1C1 = "=RC[-6]*R[-24]C"
    Range("I3").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-1]C"
    Range("I4").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-2]C"
    Range("I5").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-3]C"
    Range("I6").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-4]C"
    Range("I7").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-5]C"
    Range("I8").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-6]C"
    Range("I9").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-7]C"
    Range("I10").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-8]C"
    Range("I11").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-9]C"
    Range("I12").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-10]C"
    Range("I13").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-11]C"
    Range("I14").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-12]C"
    Range("I15").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-13]C"
    Range("I16").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-14]C"
    Range("I17").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-15]C"
    Range("I18").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-16]C"
    Range("I19").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-17]C"
    Range("I20").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-18]C"
    Range("I21").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-19]C"
    Range("I22").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-20]C"
    Range("I23").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-21]C"
    Range("I24").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-22]C"
    Range("I25").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-23]C"
    Range("I26").Select
    ActiveCell.FormulaR1C1 = "=RC[-7]*R[-24]C"
    Range("J3").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-1]C"
    Range("J4").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-2]C"
    Range("J5").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-3]C"
    Range("J6").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-4]C"
    Range("J7").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-5]C"
    Range("J8").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-6]C"
    Range("J9").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-7]C"
    Range("J10").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-8]C"
    Range("J11").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-9]C"
    Range("J12").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-10]C"
    Range("J13").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-11]C"
    Range("J14").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-12]C"
    Range("J15").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-13]C"
    Range("J16").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-14]C"
    Range("J17").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-15]C"
    Range("J18").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-16]C"
    Range("J19").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-17]C"
    Range("J20").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-18]C"
    Range("J21").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-19]C"
    Range("J22").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-20]C"
    Range("J23").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-21]C"
    Range("J24").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-22]C"
    Range("J25").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-23]C"
    Range("J26").Select
    ActiveCell.FormulaR1C1 = "=RC[-8]*R[-24]C"
    Range("K3").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-1]C"
    Range("K4").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-2]C"
    Range("K5").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-3]C"
    Range("K6").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-4]C"
    Range("K7").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-5]C"
    Range("K8").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-6]C"
    Range("K9").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-7]C"
    Range("K10").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-8]C"
    Range("K11").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-9]C"
    Range("K12").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-10]C"
    Range("K13").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-11]C"
    Range("K14").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-12]C"
    Range("K15").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-13]C"
    Range("K16").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-14]C"
    Range("K17").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-15]C"
    Range("K18").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-16]C"
    Range("K19").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-17]C"
    Range("K20").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-18]C"
    Range("K21").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-19]C"
    Range("K22").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-20]C"
    Range("K23").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-21]C"
    Range("K24").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-22]C"
    Range("K25").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-23]C"
    Range("K26").Select
    ActiveCell.FormulaR1C1 = "=RC[-9]*R[-24]C"
    Range("L3").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-1]C"
    Range("L4").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-2]C"
    Range("L5").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-3]C"
    Range("L6").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-4]C"
    Range("L7").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-5]C"
    Range("L8").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-6]C"
    Range("L9").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-7]C"
    Range("L10").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-8]C"
    Range("L11").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-9]C"
    Range("L12").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-10]C"
    Range("L13").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-11]C"
    Range("L14").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-12]C"
    Range("L15").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-13]C"
    Range("L16").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-14]C"
    Range("L17").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-15]C"
    Range("L18").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-16]C"
    Range("L19").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-17]C"
    Range("L20").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-18]C"
    Range("L21").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-19]C"
    Range("L22").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-20]C"
    Range("L23").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-21]C"
    Range("L24").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-22]C"
    Range("L25").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-23]C"
    Range("L26").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]*R[-24]C"
    Range("M3").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-1]C"
    Range("M4").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-2]C"
    Range("M5").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-3]C"
    Range("M6").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-4]C"
    Range("M7").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-5]C"
    Range("M8").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-6]C"
    Range("M9").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-7]C"
    Range("M10").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-8]C"
    Range("M11").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-9]C"
    Range("M12").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-10]C"
    Range("M13").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-11]C"
    Range("M14").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-12]C"
    Range("M15").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-13]C"
    Range("M16").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-14]C"
    Range("M17").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-15]C"
    Range("M18").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-16]C"
    Range("M19").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-17]C"
    Range("M20").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-18]C"
    Range("M21").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-19]C"
    Range("M22").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-20]C"
    Range("M23").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-21]C"
    Range("M24").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-22]C"
    Range("M25").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-23]C"
    Range("M26").Select
    ActiveCell.FormulaR1C1 = "=RC[-11]*R[-24]C"
    Range("N3").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-1]C"
    Range("N4").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-2]C"
    Range("N5").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-3]C"
    Range("N6").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-4]C"
    Range("N7").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-5]C"
    Range("N8").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-6]C"
    Range("N9").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-7]C"
    Range("N10").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-8]C"
    Range("N11").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-9]C"
    Range("N12").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-10]C"
    Range("N13").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-11]C"
    Range("N14").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-12]C"
    Range("N15").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-13]C"
    Range("N16").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-14]C"
    Range("N17").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-15]C"
    Range("N18").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-16]C"
    Range("N19").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-17]C"
    Range("N20").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-18]C"
    Range("N21").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-19]C"
    Range("N22").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-20]C"
    Range("N23").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-21]C"
    Range("N24").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-22]C"
    Range("N25").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-23]C"
    Range("N26").Select
    ActiveCell.FormulaR1C1 = "=RC[-12]*R[-24]C"
    Range("O3").Select
    ActiveCell.FormulaR1C1 = _
        "=RC[-12]+RC[-11]+RC[-10]+RC[-9]+RC[-8]+RC[-7]+RC[-6]+RC[-5]+RC[-4]+RC[-3]+RC[-2]+RC[-1]"
    Range("O3").Select
    Selection.AutoFill Destination:=Range("O3:O26"), Type:=xlFillDefault
    Range("O3:O26").Select
End Sub

1 个答案:

答案 0 :(得分:2)

在OP的评论后编辑

试试这个:

Option Explicit

Sub Macro1()
    Dim i As Long

    For i = 2 To Worksheets.count
        With Worksheets(i).Range("C3:O26")
            .Resize(, Columns.count - 1).FormulaR1C1 = "=RC2*R2C"
            .Columns(.Columns.count).Resize(, 1).FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
            .NumberFormat = "$#,##0.00"
        End With
    Next
End Sub