如何在范围内引用范围

时间:2019-12-26 04:37:14

标签: excel vba excel-formula

Option Explicit

Sub Generate_AcEntries()
    Application.ScreenUpdating = False

    'Declaring formula from F3 until F 29 for AC_Entries
    With ActiveWorkbook.Worksheets("Ac_Entries")
        'Formula for Amount
        .Range("F34").Formula = "=Prudential!$G$89"
        .Range("F35").Formula = "=Prudential!$G$90"
        .Range("F36").Formula = "=Prudential!$G$91"
        .Range("F37").Formula = "=AIA!$G$133"
        .Range("F38").Formula = "=AIA!$G$141"
        .Range("F39").Formula = "=0"
        .Range("F40").Formula = "=AIA!$G$111"
        .Range("F41").Formula = "=AIA!$G$121"
        .Range("F42").Formula = "=AIA!$G$161"
        .Range("F43").Formula = "=AIA!$G$170"
        .Range("F44").Formula = "=AIA!$G$179"
        .Range("F45").Formula = "=AIA!$G$188"
        .Range("F46").Formula = "=AIA!$G$197"
        .Range("F51").Formula = "=SUM(F3:F50)"


        'For Description
        .Range("G34") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), 2) & " PRU auto RB 15 USD"
        .Range("G35") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), 2) & " PRU auto RB 25 IDR"
        .Range("G36") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), 0)), 2) & " PRU auto RB 25 USD"
        .Range("G37") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -2)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -2)), 2) & " AIA PCP DIGITAL"
        .Range("G38") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & " AIA IDR OMNI"
        .Range("G39") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & " AIA USD OMNI"
        .Range("G40") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & " AIA CS Adj Comm RC"
        .Range("G41") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & " AIA CS Adj Comm CC"
        .Range("G42") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & Sheets("Other").Range("E13")
        .Range("G43") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & Sheets("Other").Range("E14")
        .Range("G43") = "Pjk" & MonthName(Month(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), True) & Right(Year(WorksheetFunction.EoMonth(ActiveWorkbook.Sheets("Main").Range("C4"), -1)), 2) & Sheets("Other").Range("E15")
  

范围42上的错误,并带有以下错误提示:下标超出范围

  1. 如何在范围内引用范围,因为我添加了代码

&Sheets(“ Other”).. range(“ G42”)上的Range(“ E14”)吗?

0 个答案:

没有答案