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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,216,073
Messages
6,128,634
Members
449,460
Latest member
jgharbawi

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