【发布时间】:2021-11-03 07:11:16
【问题描述】:
我编写了代码以在消息框中显示字符串(st1、st2、st3、...)中的文本,因为它正在通过For 循环,但它只显示为数字.
我希望下面的代码在其第一个 For 循环中输出 txt : Test A。但它给了我txt : 1。所以在整个循环中,它只会显示循环号而不是字符串中的文本。请帮忙。
Sub OutputTxt()
'States of the prosessing----------------------------
Dim stat As String
'string values - Discriptions
Dim st1 As String
Dim st2 As String
Dim st3 As String
Dim st4 As String
Dim st5 As String
Dim st6 As String
Dim st7 As String
Dim st8 As String
st1 = "Test A"
st2 = "Test B"
st3 = "Test C"
st4 = "Test D"
st5 = "Test E"
st6 = "Test F"
st7 = "Test G"
st8 = "Test H"
'-----------------------------------------------------------
Dim Counter As Long
Dim TotalCount As Long
'Initialize the Variables and Objects
TotalCount = 8
For Counter = 1 To TotalCount
stat = st & Counter
'Update the msg box
MsgBox ("Txt : " & stat)
Next Counter
End Sub
【问题讨论】:
标签: excel vba messagebox