获取编译错误“找不到变量”,它突出显示C.这是一个简单的代码,我不知道为什么我收到此错误。范围在静态选项卡上定义,一切看起来都很好。请帮忙!
Sub RunPull()
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Sheets("STATIC").Select
For Each C In Worksheets("STATIC").Range("RunRange").Cells
Calculate
Sheets("STATIC").Range("RunTag") = C
RunSeperateMacro
Next
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
答案 0 :(得分:0)
您无法在代码中初始化名为 C 的变量。这将正常工作:
Sub RunPull()
Dim C as Variant
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Sheets("STATIC").Select
For Each C In Worksheets("STATIC").Range("RunRange").Cells
Calculate
Sheets("STATIC").Range("RunTag") = C
RunSeperateMacro
Next
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
或者,您可以查看此语句是否出现在模块的顶部并将其删除:
Option Explicit
这行代码强制您明确声明所有变量。