“编译错误:types不匹配”

我有简单的VBA程序,它需要检查一个范围,并告诉用户是否有任何空单元格 – 如果是,哪些单元格。

问题是这样的:

Dim outputsrange("inputnum+1:inputnum+outputnum") As range 

function:

 Sub check() ' Goal: check if there are any entry truth table cells for outputs Dim outputsrange("inputnum+1:inputnum+outputnum") As range If IsEmpty(outputsrange) Then MsgBox ("The following cells are empty:" & vbNewLine & emptycell) ' what's the property for these empty cells End If End Sub 

这给了错误:

编译错误:

types不匹配

我如何解决这种types的不匹配?

你可以尝试更接近这一点。

 Dim outputsrange As range Set outputsrange = Range(inputnum + 1 & ":" & inputnum + outputnum) 

将inputnum设置为1,将outputnum设置为5,应将输出范围设置为第2到第6行。