For Each cell In wb.Sheets("RP Analysis").Range("F5:F" & lastRow)
structure = "Layer " & WorksheetFunction.RoundDown(cell.Value, 2) & ": " & WorksheetFunction.RoundDown(cell.Offset(0, 2).Value / 1000000, 2) & " xs " & WorksheetFunction.RoundDown(cell.Offset(0, 3).Value / 1000000, 2) & " attaches at "
RMS = RMS & structure & WorksheetFunction.RoundDown(cell.Offset(0, 10).Value, 2) & "m and exhausts at " & WorksheetFunction.RoundDown(cell.Offset(0, 11).Value, 2) & "m" & vbLf
AIR = AIR & structure & WorksheetFunction.RoundDown(cell.Offset(0, 6).Value, 2) & "m and exhausts at " & WorksheetFunction.RoundDown(cell.Offset(0, 7).Value, 2) & "m" & vbLf
Next cell
For Each cell In wb.Sheets("RP Analysis").Range("A9:A" & 19)
gucurve = gucurve & cell.Value & ":- " & Format(cell.Offset(0, 2).Value / cell.Offset(0, 1).Value, "Percent") & vbLf
Next cell
TextBox1.Value = "RP years RMS/AIR difference" & vbLf & gucurve & vbLf & "AIR" & vbLf & AIR & vbLf & "RMS" & vbLf & RMS
这会产生
Layer 1: 25 xs 50 attaches at 8.16m and exhausts at 10.4m
Layer 2: 100 xs 75 attaches at 10.4m and exhausts at 20.15m
Layer 3: 44 xs 175 attaches at 20.15m and exhausts at 24.96m
Layer 4: 144 xs 175 attaches at 20.15m and exhausts at 34.86m
我想要它产生
Layer 1: 25 xs 50 attaches at 8.16m and exhausts at 10.4m
Layer 2:100 xs 75 attaches at 10.4m and exhausts at 20.15m
Layer 3: 44 xs 175 attaches at 20.15m and exhausts at 24.96m
Layer 4:144 xs 175 attaches at 20.15m and exhausts at 34.86m
所以我认为我需要具有定义宽度的固定列,并且所有内容都居中。数字永远不会超过 4 位
我该如何解决这个问题?
最佳答案
您可以使用 Format
和 @
符号来填充并对齐右侧的每个值:
Format("123", "@@@@@@@@@@") ' returns " 123"
或者在左边:
Format("123", "!@@@@@@@@@@") ' returns "123 "
并通过提供字符数:
Format("123", String(25, "@")) ' returns " 123"
关于vba - 文本框 VBA 中的固定宽度列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38771468/