Create Macro With Several Variables
Posted
by Daniel
on Stack Overflow
See other posts from Stack Overflow
or by Daniel
Published on 2010-05-17T19:17:48Z
Indexed on
2010/05/17
19:20 UTC
Read the original article
Hit count: 122
I have several worksheets with similar code, so I'd like to turn it into a macro. My only problem is that there are several variables. So at certain points the code looks like this:
Dim Msg_1 As String
Dim Msg_2 As String
Public Sub ListBox1_LostFocus()
ListBox1.Height = 15
With ListBox1
Msg1 = "'"
For i = 0 To .ListCount - 1
If .Selected(i) Then
Msg1 = Msg1 & .List(i) & "','"
End If
Next i
End With
Msg1 = Left(Msg1, Len(Msg1) - 2)
Sheets("Sheet1").Range("R3", "R3") = Msg1
End Sub
and so on. How can I pass in a new value for Msg1, Msg2, Msg3 for each worksheet?
© Stack Overflow or respective owner