如何使VBA函数将If,then语句的结果输​​出到单元格?

时间:2018-06-27 17:20:33

标签: excel vba

这是我第一次进行任何编码,因此很抱歉,它可能会更好。我的问题是,当我尝试使用此函数时,仅在单元格中收到#VALUE错误,我不知道为什么。 该程序应该获取用户输入的任何信息,并决定该特定连接器是否适用于指定的输入。连接器是否工作取决于可使用的电缆以及用户输入的连接器类型。

Function CONNECTOR1(Cable As Double, Connector As String, Row As Double) As String
    CableI = Worksheets("Sheet1").Range("A4").String
    ConnectorI = Worksheets("Sheet1").Range("B4").String
    MaxdBLossI = Worksheets("Sheet1").Range("D4").Value
    ConnectorTypeI = Worksheets("Sheet1").Range("E4").String
    If IsEmpty(CableI) = True And IsEmpty(ConnectorI) = True And Not IsEmpty(MaxdBLossI) And Not IsEmpty(ConnectorTypeI) Then
        If ConnectorTypeI = Worksheets("Sheet1").Range("I" & Row).Value And Application.WorksheetFunction.CountIf(Range("N3:N500"), Cable) Then
            CONNECTOR1 = Connector
        End If
    ElseIf IsEmpty(ConnectorTypeI) = True And CableI = Cable Then
        CONNECTOR1 = Connector
    ElseIf CableI = "" Then
        If Application.WorksheetFunction.CountIf(Range("N3:N500"), Cable) Then
            CONNECTOR1 = Connector
        End If
    ElseIf ConnectorTypeI = Worksheets("Sheet1").Range("I" & Row).Value And CableI = Cable Then
        CONNECTOR1 = Connector
    Else
        CONNECTOR1 = Worksheets("Sheet2").Range("O" & Row).ClearContents
    End If
End Function
'The goal of this code is for it to decide based on which inputs the user has given, if a certain connector will satisfy the criteria
'Connectors only work for a specific number of cables, so this set of code is only for a connector that works with one cable
'CableI is a cable part number input by the user
'ConnectorI is a connector part number input by the user
'MaxdBLossI is an input amount of acceptable signal loss
'ConnectorTypeI is an input for the specific type of connector needed`

0 个答案:

没有答案