Show a string by index part of name

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,099
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I've some strings called "MyEncode1", "MyEncode2", "MyEncode3" etc and
passing 1 2 or 3 to a function (as n), wanting to see the one corresponding to n.

It won't work! I can go to the immediate window and debug print e.g. MyEncode2 fine
but debug print MyEncode & n fails.

There's probably a simple solution but it eludes me.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I would use an array of strings. Something like.

Code:
Sub aTest()
    Dim MyEncode() As String, n As Integer
    
    ReDim MyEncode(1 To 3)
    MyEncode(1) = "String 1"
    MyEncode(2) = "String 2"
    MyEncode(3) = "String 3"
    
    n = 2
    MsgBox MyEncode(n)
End Sub

M.
 
Upvote 0
Hi Marcelo.. after some playing around, I ended up with something very similar (but using Array).
Thanks for confirming there's no other method..
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top