+ Reply to Thread
Results 1 to 3 of 3

Using Integer to return value of multiple different Dim Values in loop

  1. #1
    Registered User
    Join Date
    08-09-2022
    Location
    United States
    MS-Off Ver
    Version 2206
    Posts
    4

    Question Using Integer to return value of multiple different Dim Values in loop

    Code Returns The First "T1 - 6" as text and not the value of T1 - 6. Is there a way to tell VBA to return the value of the constructed name and not just the constructed name?


    Sub Example()

    Dim T1 As String
    Dim T2 As String
    Dim T3 As String
    Dim T4 As String
    Dim T5 As String
    Dim T6 As String
    Dim X As Integer

    T1 = "text one"
    T2 = "text two"
    T3 = "text three"
    T4 = "Text four"
    T5 = "text five"
    T6 = "Text six"

    For X = 1 To 6

    MsgBox (("T" & X) & " " & T1)

    Next X

    End Sub

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Using Integer to return value of multiple different Dim Values in loop

    I'm not sure what you have tried, but, assuming you are unfamiliar with arrays in VBA (or other programming languages), the usual approach to this is to use an array for storing those strings.

    Please Login or Register  to view this content.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    08-09-2022
    Location
    United States
    MS-Off Ver
    Version 2206
    Posts
    4

    Re: Using Integer to return value of multiple different Dim Values in loop

    You assumed correctly. Thank you the array method works great.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Which is faster: For-loop or For Each-loop with integer?
    By Rezzy777 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-12-2021, 05:29 AM
  2. VBA Loop Until cell = integer
    By Koehlr2 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-07-2020, 08:47 PM
  3. [SOLVED] Loop, match and return values
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-31-2018, 11:06 AM
  4. [SOLVED] Input a range of values into a cell and return the values for each loop
    By cavalieregiuseppe in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-10-2018, 11:31 PM
  5. [SOLVED] Loop on the Row as integer, getting integer into a range
    By Fean in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2018, 07:16 AM
  6. [SOLVED] For loop to return multiple values from another worksheet
    By shre0038 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-06-2014, 11:30 AM
  7. Dim integer in For loop does not work, why?
    By 123wc in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-30-2011, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1