我公司目前有以下功能的代碼,引用命名的單元格工作表Sheet1上分別:WorksheetFunction.CountA另一個頁面上使用命名的單元格
Dim emp1 As Boolean
Dim emp2 As Boolean
Dim emp3 As Boolean
With Sheet1
If WorksheetFunction.CountA(.Range("AI"), .Range("AM"), .Range("AQ")) = 0 And wVOE1 = False And IsEmpty(.Range("DQ")) Then
emp1 = False
Else
emp1 = True
End If
If WorksheetFunction.CountA(.Range("FH"), .Range("FL"), .Range("FP")) = 0 And wVOE2 = False And IsEmpty(.Range("IV")) Then
emp2 = False
Else
emp2 = True
End If
If WorksheetFunction.CountA(.Range("KL"), .Range("KP"), .Range("KT")) = 0 And wVOE3 = False And IsEmpty(.Range("NZ")) Then
emp3 = False
Else
emp3 = True
End If
End With
最後,我想學習如何使用COUNTA函數用而不是引用單個細胞。我原本試過下面的代碼,這是行不通的:
Dim emp1 As Boolean
Dim emp2 As Boolean
Dim emp3 As Boolean
With Sheet1
If WorksheetFunction.CountA(Range("AI:AT")) = 0 And wVOE1 = False And IsEmpty(Sheet1.[DQ]) = True Then _
emp1 = False _
Else _
emp1 = True
If WorksheetFunction.CountA(Range("FH:FS")) = 0 And wVOE2 = False And IsEmpty(Sheet1.[IV]) Then _
emp2 = False _
Else _
emp2 = True
If WorksheetFunction.CountA(Range("KL:KW")) = 0 And wVOE3 = False And IsEmpty(Sheet1.[NZ]) Then _
emp3 = False _
Else _
emp3 = True
End With
我很難搞清楚爲什麼後面的代碼不起作用。有沒有辦法引用範圍?在此先感謝您的幫助。
'沒work' - 它是怎麼不行?如果範圍在不同的工作表上,您將需要限制工作表,如下所示:'Sheet2.Range(「AI:AT」)'或'Sheet3.Range(「AI:AT」)''。或'Worksheet(「Sheet2」)。範圍(「AI:AT」)' –
emp1,emp2和emp3僅依賴於變量wVOE1,wVOE2和wVOE3。例如,如果wVOE = false並且sheet1。[AI]被填充,則emp1將返回爲false。 @ScottHoltzman – Kim
當我限定爲:WorksheetFunction.CountA(Sheet1.Range(「AI:AT」))時,即使填滿單元格,也會返回0。我也嘗試了Worksheet(「Sheet1」)。Range(「AI:AT」),它也返回0. @ScottHoltzman – Kim