Is this possible in theory? - Workaround needed working with variables

sramsay

Board Regular
Joined
Feb 19, 2015
Messages
96
I posted a few days ago looking for a solution to this but didn't get much back, however, it was a rather complex way of putting it, so I am hoping by recreating the issue in a simple scenario, I may just get some help :)

Code:
Sub varTest()


Dim i As Integer
Dim theSum As Integer


    i = 1
    X = Left("integer", 1) 'returns the letter 'i', the 1st variable's name
    
    Debug.Print i 'at this point, this returns the number 1
    Debug.Print X 'at this point, this returns the letter i
    
    theSum = X + i 'Essentially, I would want this to be 1+1
    
    Debug.Print theSum
    Debug.Print "The answer I need to get is 2, but it errors"


End Sub
 
so this is the concept...

Code:
Sub test_load_f1()


Dim transRange As Range
Dim transLr As Long
Dim varName As Variant


transLr = Sheets("TranslationTable").Range("A1048576").End(xlUp).row
Set transRange = Sheets("TranslationTable").Range("A2:E" & transLr)


Dim c As MSForms.Control
     
    For Each c In Userform1.fra_ten12mnth.Controls
        If TypeOf c Is MSForms.TextBox Then
            [U]varName[/U] = Application.VLookup(Replace(c.Name, "tb_ten12", ""), transRange, 2, False)
            c.value = Sheets("Commited Data").Cells(Sheets("Commited Data").Range("A:A").Find(What:=vTenId & "12" & vTenSupplier & vTenMeterNumber, LookAt:=xlWhole).row, [U]varName[/U]).value
        ElseIf TypeOf c Is MSForms.CheckBox Then
            '...
        Else
            
        End If
    Next c
    
End Sub
 
Last edited:
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You need to have your lookup table return the column index, so this:
Rich (BB code):
Application.VLookup(Replace(c.Name, "tb_ten12", ""), transRange, 2, False)
Should return a Long. You could use a formula in the second column to dynamically update the column index if you wanted to make dynamic, but I'd probably use a collection
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,370
Members
449,155
Latest member
ravioli44

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