最初にベース文字列を次のように変更します
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
A5 から D5 の範囲の値がシート 1 に格納されていると想定しています。
編集
スナップショット
HTH