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
我试过这段代码,但似乎这比我预想的要复杂得多。看看帖子和避风港解决问题的好运。输出错误。
代码假设执行以下操作:
如果给定尺寸小于&#34; 24 x 16.5 x 0.5&#34;,则它应将输出结果显示为&#34; Letter&#34;。
如果给定尺寸小于&#34; 35.3 x 25 x 2.5&#34;,则它应将输出结果显示为&#34;大字母&#34;。
< / LI>如果给定尺寸小于&#34; 45 x 35 x 16&#34;,则应将输出结果显示为&#34; Small Parcel&#34;。
任何大于指定尺寸的东西都应打印出来&#34; Medium Parcel&#34;。
非常感谢任何帮助,我现在已经坚持这个问题很长一段时间了:(
尺寸列表:
答案 0 :(得分:0)
一个很好的挑战!
尝试以下功能:
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