首先将您的基本字符串更改为这样的
BaseString = "Your vehicle selection of {VEHSEL} indicates you should have " & _
"between {nTYRE1} and {nTYRE2} tires. However, you have entered " & _
"{nTotTYRE} tires for this vehicle. Please update the record " & _
"accordingly."
如果您现在注意到您有特定的关键字,例如
VEHSEL - Vehicle Selection
nTYRE1 - Lowest selection of tires
nTYRE2 - Highest selection of tires
nTotTYRE - Total tires selected
从电子表格中获取值后,只需使用相关值REPLACE
替换上述关键字
所以你的代码看起来像
Option Explicit
Sub Sample()
Dim lVSell As Long, lT1 As Long, lT2 As Long, ltotT As Long
Dim lRowID As Long
lRowID = 5
With Sheets("Sheet1")
lVSell = .Range("A" & lRowID).Value
lT1 = .Range("B" & lRowID).Value
lT2 = .Range("C" & lRowID).Value
ltotT = .Range("D" & lRowID).Value
Debug.Print ShowMsg(lRowID, lVSell, lT1, lT2, ltotT)
End With
End Sub
Function ShowMsg(ByVal RowID As Integer, ByVal VSel As Long, _
ByVal T1 As Long, ByVal T2 As Long, ByVal totT As Long) As String
Dim BaseString As String
BaseString = "Your vehicle selection of {VEHSEL} indicates you should have " & _
"between {nTYRE1} and {nTYRE2} tires. However, you have entered " & _
"{nTotTYRE} tires for this vehicle. Please update the record " & _
"accordingly."
BaseString = Replace(BaseString, "VEHSEL", VSel)
BaseString = Replace(BaseString, "nTYRE1", T1)
BaseString = Replace(BaseString, "nTYRE2", T2)
BaseString = Replace(BaseString, "nTotTYRE", totT)
ShowMsg = BaseString
End Function
我假设这些值存储在表 1 中,范围从 A5 到 D5。
编辑
快照
高温高压