如何让VBA(excel)告诉我代码停止的单元格

我希望这是可能的。 我想知道如何使excel告诉我在什么单元格遇到我的预定义的“错误”。 例如部分代码是这样的:

Sub CheckErrors() For Each Cel In Range("A3:A400") If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 6)) = True Then Msgbox "Add a description (name) when creating" End If End If If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 7)) = True Then Msgbox "Please choose type when creating" Exit For End If End If Next 

我想要的消息框还包括什么特定的单元格excel发现空。 所以如果在A列中有CR,那么列G必须有一个描述,如果G3是空的,而A3中有CR,那么我想让消息框在创build时添加一个描述(名称),修改单元格G3。

任何帮助表示赞赏。 我很新的VBA和编码,所以即使是最基本的可能会有所帮助!

问候吉姆

那么,你可以在MSGBOX添加属性.address …这样:

 Sub CheckErrors() For Each Cel In Range("A3:A400") If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 6)) = True Then Msgbox "Add a description (name) when creating " & Cel.Offset(0, 6).address End If End If If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 7)) = True Then Msgbox "Please choose type when creating " & Cel.Offset(0, 7).address Exit For End If End If Next End Sub 

你的问题含糊不清,请提供更多关于你真正想要什么的信息,你做了什么来达到这个目标,你有什么错误或者其他的结果。

编辑

Nick Dewitt的评论中,你会看到你需要replace地址Replace(Cel.Offset(0, 6).address, "$", "")$ Replace(Cel.Offset(0, 6).address, "$", "")

编辑#2

 Sub CheckErrors() For Each Cel In Range("A3:A400") If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 6)) = True Then Msgbox "Add a description (name) when creating " & Replace(Cel.Offset(0, 6).address, "$", "") End If End If If Cel.Value = "CR" Then If IsEmpty(Cel.Offset(0, 7)) = True Then Msgbox "Please choose type when creating " & Replace(Cel.Offset(0, 6).address, "$", "") Exit For End If End If Next End Sub