【问题标题】:Excel - Macro Changing sheets and Fill to End - Compile ErrorExcel - 宏更改工作表并填充到结尾 - 编译错误
【发布时间】:2013-03-28 00:33:58
【问题描述】:

我正在创建一个宏以在大约 25 张纸上连续运行,我在其中命名特定列中的单元格。我有填写结束和更换工作表的代码。但是当我合并代码时,我收到了一个警告:

编译错误:当前范围内的重复声明

当我删除 DIM 定义时,它将在连续的工作表上运行,但只运行到第一张工作表的末尾。我的目标是让每张工作表动态填充以在 N 列结束,并为每个工作表设置一个名称。

这是我正在处理的代码

    Sub Mailbox_Name()
'
' Mailbox_Name Macro
' Adds Mailbox Name to Each Sheet

'
    Dim LR As Long
    LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("N1").Select
    ActiveCell.FormulaR1C1 = "Mailbox"
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "ACC"
    Range("N2").Select
    Selection.AutoFill Destination:=Range("N2:N" & LR)
    Range("N2:N" & LR).Select

    Selection.Copy
    Sheets("ACPR").Select
    Dim LR As Long
    LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("N1").Select
    ActiveCell.FormulaR1C1 = "Mailbox"
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "ACPR"
    Range("N2").Select
    Selection.AutoFill Destination:=Range("N2:N" & LR)
    Range("N2:N" & LR).Select
End Sub

感谢您提供的任何帮助!

【问题讨论】:

    标签: excel compiler-errors autofill vba


    【解决方案1】:

    只需阅读错误告诉你的内容 - 你有一个重复的声明。果然,在你的代码中你有两次Dim LR As Long

    【讨论】:

    • 谢谢...我将声明重置为 Dim LR1 之类的东西,然后它运行了。我希望有一种更简单的方法来重新声明,这样我就可以花更少的时间清理宏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 2023-01-11
    相关资源
    最近更新 更多