Excel VBA代码不能完全工作,除非删除了某些部分

我的问题是,当我写所有的代码,其中一个将不起作用。 它不会给出错误信息,但GenerateEmail子目录中不会生成电子邮件。 但是,如果我删除了一个While Wend代码,其他工作(我一个接一个地testing)。 简而言之,如果所有的Wend代码都存在,那么其中的一个将不起作用。 我不知道发生了什么事。 任何帮助表示赞赏。 我试过find类似的情况,但没有成功。

我的代码:

Sub CaseCreation() Dim subjectTitleEABS As String Dim subjectTitleCCC As String Dim subjectTitleRR As String Dim subjectTitleTERM As String Dim rowCount As String rowCount = 2 While Sheets("Extended Abs").Range("B" & CStr(rowCount)).Value <> "" If Sheets("Extended Abs").Range("A" & CStr(rowCount)).Value = "" Then subjectTitleEABS = Sheets("Extended Abs").Range("K" & CStr(rowCount)).Value Call GenerateEmail(subjectTitleEABS) End If rowCount = rowCount + 1 Wend While Sheets("Contractual Conditions Change").Range("B" & CStr(rowCount)).Value <> "" If Sheets("Contractual Conditions Change").Range("A" & CStr(rowCount)).Value = "" Then subjectTitleCCC = Sheets("Contractual Conditions Change").Range("L" & CStr(rowCount)).Value Call GenerateEmail(subjectTitleCCC) End If rowCount = rowCount + 1 Wend While Sheets("Resource Requests").Range("B" & CStr(rowCount)).Value <> "" If Sheets("Resource Requests").Range("A" & CStr(rowCount)).Value = "" Then subjectTitleRR = Sheets("Resource Requests").Range("M" & CStr(rowCount)).Value Call GenerateEmail(subjectTitleRR) End If rowCount = rowCount + 1 Wend While Sheets("Terminations").Range("B" & CStr(rowCount)).Value <> "" If Sheets("Terminations").Range("A" & CStr(rowCount)).Value = "" Then subjectTitleTERM = Sheets("Terminations").Range("K" & CStr(rowCount)).Value Call GenerateEmail(subjectTitleTERM) End If rowCount = rowCount + 1 Wend 

只有第一个时间/我们会执行。 例如,如果你有5行,你的第二行将从rowCount 6开始。你需要在每个While / Wend之间重置你的计数器。