复杂的条件与做到

Do Until Selection.Value = "" Or _ (Selection.Value = theyear And Selection.Offset(0, 1).Value = themonth) Selection.Offset(1, 0).Select Loop 

在这一行的声明中,代码无法检查与部分ie的条件; 它不检查括号中的条件。 是否预计?

尝试这个:

 Sub Test() Dim sMonth As String Dim iYear As Integer sMonth = UCase(Trim(InputBox("Enter the first three alphabets of the month to append", "Month Initials"))) iYear = InputBox("Enter the year to which the month corresponds", "Year") Do Until Selection.Value = "" Or _ (UCase(Trim(Selection.Value)) = sMonth And Selection.Offset(0, 1).Value = iYear) Selection.Offset(1, 0).Select Loop End Sub 

你的主要错误是在引号之间加上一个variables名。 不过,我想指出的是,这个代码可能对错误非常明智,因为您允许用户input任何数据而不用检查。
但如果是为了自己使用,这并不重要。
另外请注意。select/偏移使您的代码整体非常严格。