Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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
使用IF语句比较维度和返回语句-VBA 子维度() 作为整数的Dim i LastRow=工作表(“日志”).范围(“C3”).特殊单元格(xlCellTypeLastCell).行 对于i=3到最后一行 如果工作表(“日志”).Range(“C”&i).Value_Vba_Excel_If Statement_Nested If - Fatal编程技术网

使用IF语句比较维度和返回语句-VBA 子维度() 作为整数的Dim i LastRow=工作表(“日志”).范围(“C3”).特殊单元格(xlCellTypeLastCell).行 对于i=3到最后一行 如果工作表(“日志”).Range(“C”&i).Value

使用IF语句比较维度和返回语句-VBA 子维度() 作为整数的Dim i LastRow=工作表(“日志”).范围(“C3”).特殊单元格(xlCellTypeLastCell).行 对于i=3到最后一行 如果工作表(“日志”).Range(“C”&i).Value,vba,excel,if-statement,nested-if,Vba,Excel,If Statement,Nested If,是一个很好的挑战 请尝试以下功能: Sub Dimensions() Dim i As Integer LastRow = Sheets("Log").Range("C3").SpecialCells(xlCellTypeLastCell).Row For i = 3 To LastRow If Sheets("Log").Range("C" & i).Value <= "24 x 16.5 x 0.5" Then Sh

是一个很好的挑战

请尝试以下功能:

Sub Dimensions()

    Dim i As Integer

    LastRow = Sheets("Log").Range("C3").SpecialCells(xlCellTypeLastCell).Row

    For i = 3 To LastRow
        If Sheets("Log").Range("C" & i).Value <= "24 x 16.5 x 0.5" Then
        Sheets("Log").Range("I" & i).Value = "Letter"

        ElseIf (Sheets("Log").Range("C" & i).Value <= "35.3 x 25 x 2.5") And (Sheets("Log").Range("C" & i).Value > "24 x 16.5 x 0.5") Then
        Sheets("Log").Range("I" & i).Value = "Large Letter"

        ElseIf (Sheets("Log").Range("C" & i).Value <= "45 x 35 x 16") And (Sheets("Log").Range("C" & i).Value > "35.3 x 25 x 2.5") Then
        Sheets("Log").Range("I" & i).Value = "Small Parcel"

        Else
        Sheets("Log").Range("I" & i).Value = "Medium Parcel"

        End If
    Next i
End Sub

不,我想比较一下这两种尺寸。例如,如果“2.3 x 2.3 x 0.5”小于“24 x 16.5 x 0.5”,那么输出结果应该是“字母”,为什么不在维度表中添加一个额外的列,说明每个列是什么类别,然后执行
VLookup
。在这种情况下,VLookup不起作用,因为我需要调整代码以考虑重量,这是我代码中的下一步。但我现在正在努力解决基本问题。。。如果您看到该图像,您将能够看到我的意思是从选择列表中选择的单元格值(因此您知道可能存在的所有潜在单元格值)或者它们是用户以随机格式输入的-例如,用户是否可以输入
23 x 30 x 2
,需要将其视为大于
24 x 16.5 x 0.5
,但小于
35.3 x 25 x 2.5
?是,用户可以输入23x30x2,程序应将其视为大于24 x 16.5 x 0.5但小于35.3 x 25 x 2。5@ArsalanRana-嗯-这是第一张唱片吗?或者有些记录已经被处理过了,但只在一部分数据中崩溃了?非常感谢!我已经相应地调整了代码,它就像一个符咒!现在,我将尝试通过实现要考虑的权重属性=D来增加您的工作量
Function LetterSize(s As String) As String
    'Break source string into the three dimensions
    Dim a() As String
    a = Split(s, "x") 
    'Convert to numeric values
    Dim d(1 To 3) As Double
    d(1) = CDbl(a(0))
    d(2) = CDbl(a(1))
    d(3) = CDbl(a(2))
    'Sort into ascending dimension size
    Dim dt As Double
    If d(1) > d(2) Then dt = d(1): d(1) = d(2): d(2) = dt
    If d(1) > d(3) Then dt = d(1): d(1) = d(3): d(3) = dt
    If d(2) > d(3) Then dt = d(2): d(2) = d(3): d(3) = dt
    Debug.Print d(1) & " x " & d(2) & " x " & d(3)

    'Determine category
    If d(1) <= 0.5 And d(2) <= 16.5 And d(3) <= 24 Then
        LetterSize = "Letter"
    ElseIf d(1) <= 2.5 And d(2) <= 25 And d(3) <= 35.3 Then
        LetterSize = "Large Letter"
    ElseIf d(1) <= 16 And d(2) <= 35 And d(3) <= 45 Then
        LetterSize = "Small Parcel"
    Else
        LetterSize = "Medium Parcel"
    End If
End Function
For i = 3 To LastRow
    Sheets("Log").Range("I" & i).Value = LetterSize(Sheets("Log").Range("C" & i).Value)
Next i