Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA电子表格,在一个电子表格中使用5个下拉框从10个发货人中选择一个_Vba_Excel - Fatal编程技术网

VBA电子表格,在一个电子表格中使用5个下拉框从10个发货人中选择一个

VBA电子表格,在一个电子表格中使用5个下拉框从10个发货人中选择一个,vba,excel,Vba,Excel,我有一个excel电子表格,用户在其中操纵5个下拉菜单,从10个装运选项中选择他们应该使用的选项 我正在使用VBA为结果编写函数。对于第二个和第三个下拉列表,我需要它对照两个大约6个州的列表进行检查。如果两个州出现在同一个列表上,我希望它根据它们出现在哪个列表上选择shipperA或shipperB。最简单的方法是什么?谢谢大家! 下面的代码: Function shipperPicker(o, oS, dS, w, p, d) As String If w = "Under 150" The

我有一个excel电子表格,用户在其中操纵5个下拉菜单,从10个装运选项中选择他们应该使用的选项

我正在使用VBA为结果编写函数。对于第二个和第三个下拉列表,我需要它对照两个大约6个州的列表进行检查。如果两个州出现在同一个列表上,我希望它根据它们出现在哪个列表上选择shipperA或shipperB。最简单的方法是什么?谢谢大家!

下面的代码:

Function shipperPicker(o, oS, dS, w, p, d) As String

If w = "Under 150" Then
    shipperPicker = "FedEx Ground" 
ElseIf o = "Store" And d = "Under 75 Miles" Then
    shipperPicker = "Matrix"
ElseIf w = "Under 150" And p = "Samples" Then
    shipperPicker = "Fedex Ground, $10 per 3 samples"
ElseIf w = "Under 150" And p = "Molding" Then
    shipperPicker = "FedEx Ground, $20"
ElseIf w = "Over 8 000" Then
    shipperPicker = "Chasity in transportation"
ElseIf p = "Laminate, Vinyl, 5/8 inch Bamboo" Then
    shipperPicker = "FedEx Freight"
ElseIf oS = "foo" Then
    shipperPicker = "foo 2"
ElseIf dS = "foo" Then
    shipperPicker = "foo 3"
ElseIf d = "foo" Then
    shipperPicker = "foo 4"        
Else
    shipperPicker = "Call store for prefered shipper and Quote"  
End If

End Function

像这样的方法应该会奏效:

Function shipperPicker(o, oS, dS, w, p, d) As String

    Dim rngA As Range, rngB As Range

    Set rngA = ThisWorkbook.Sheets("states").Range("A1:A6")
    Set rngB = ThisWorkbook.Sheets("states").Range("B1:B6")

    If w = "Under 150" Then
        shipperPicker = "FedEx Ground"
    ElseIf o = "Store" And d = "Under 75 Miles" Then
        shipperPicker = "Matrix"
    ElseIf w = "Under 150" And p = "Samples" Then
        shipperPicker = "Fedex Ground, $10 per 3 samples"
    ElseIf w = "Under 150" And p = "Molding" Then
        shipperPicker = "FedEx Ground, $20"
    ElseIf w = "Over 8 000" Then
        shipperPicker = "Chasity in transportation"
    ElseIf p = "Laminate, Vinyl, 5/8 inch Bamboo" Then
        shipperPicker = "FedEx Freight"

    ElseIf Not rngA.Find(oS, LookIn:=xlValues, lookat:=xlWhole) Is Nothing And _
        Not rngA.Find(dS, LookIn:=xlValues, lookat:=xlWhole) Is Nothing Then

        shipperPicker = "ShipperA"

    ElseIf Not rngB.Find(oS, LookIn:=xlValues, lookat:=xlWhole) Is Nothing And _
        Not rngB.Find(dS, LookIn:=xlValues, lookat:=xlWhole) Is Nothing Then

        shipperPicker = "ShipperB"

    ElseIf d = "foo" Then
        shipperPicker = "foo 4"
    Else
        shipperPicker = "Call store for prefered shipper and Quote"
    End If

End Function