Function GetDataBasedOnSelection(ByVal galaxyChecked As Boolean, ByVal universeChecked As Boolean, _
ByVal planetChecked As Boolean) As Variant
Dim currentRow As Integer
Dim retVal(1 To 3, 1 To 4)
currentRow = 1
If galaxyChecked Then
GoSub fillInCommonValuesInThisRow
retVal(currentRow, 3) = "Galaxy"
currentRow = currentRow + 1
End If
If universeChecked Then
GoSub fillInCommonValuesInThisRow
retVal(currentRow, 3) = "Universe"
currentRow = currentRow + 1
End If
If planetChecked Then
GoSub fillInCommonValuesInThisRow
retVal(currentRow, 3) = "Planet"
currentRow = currentRow + 1
End If
GetDataBasedOnSelection = retVal
Exit Function
fillInCommonValuesInThisRow:
retVal(currentRow, 1) = "A"
retVal(currentRow, 2) = "B"
retVal(currentRow, 3) = ""
retVal(currentRow, 4) = "D"
Return
End Function
如何使用上述方法:
'Pass the actual selection (true if the checkbox is checked, false otherwise)
Range("A2:D4").Value = GetDataBasedOnSelection(True, False, True)