VBA新手。我正在尝试构建一个Dimensions值(从excel电子表格中的两个不同单元格中提取,其中一个可能比另一个大,并且我总是想先使用较小的数字)在其中输出(将被串联的字符串)以及来自其他函数的字符串)可能是以下之一:
4868(无x分隔整数值)48x60.5(x分隔整数和实数)36.5x60(x分隔实数和整数)24.75x72.125(x分隔实数和整数)
在VBA中,变量类型被定义为Single(不是Double)。这是我的代码:
Function getDimDisplay(h As Single, w As Single) As String
Dim strResult As String
Dim iH As Integer
Dim iW As Integer
Dim strH As Variant
Dim strW As Variant
iH = CInt(h)
iW = CInt(w)
Select Case h
Case (h >= w And iH = h And iW = w)
strH = CStr(iH)
strW = CStr(iW)
strResult = strW & strH
Case (h >= w And iH <> h And iW = w)
strH = CStr(h)
strW …Run Code Online (Sandbox Code Playgroud)