Show a string by index part of name

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,072
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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