Determining Value Assigned To Computed Variable

D

Dave Sharpe

I need the following to use the the Value
assigned to the Variable not the Name of the
Variable ( ex "ItemCode" not ColName1 );
see "<--- here" below.

All assistance will be appreciated.

Thanks

Dave


Option Explicit

Sub test()

Dim ColName1 As String
ColName1 = "ItemCode"

Dim ColName2 As String
ColName2 = "Quantity"

Dim ColName3 As String
ColName3 = "PriceQuote"

Dim curSheetCol
Dim ColHead

curSheetCol = 1
For curSheetCol = 1 To 3

ColHead = "ColName" & curSheetCol

Debug.Print ColHead ' <---- here

Next curSheetCol


End Sub
 
K

Ken Halter

How about....
Dim ColName(3) As String
ColName(1) = "ItemCode"
ColName(2) = "Quantity"
ColName(3) = "PriceQuote"
For curSheetCol = 1 To 3

ColHead = ColName(curSheetCol)

Debug.Print ColHead ' <---- here

Next curSheetCol

Other than that, you can't do it.
 
B

Bob Butler

Dave Sharpe said:
I need the following to use the the Value
assigned to the Variable not the Name of the
Variable ( ex "ItemCode" not ColName1 );
see "<--- here" below.

All assistance will be appreciated.

Thanks

Dave


Option Explicit

Sub test()

Dim ColName(1 to 3) As String
ColName(1)="ItemCode"
ColName(2)="Quantity"
ColName(3)="PriceQuote"
Dim curSheetCol
curSheetCol = 1
For curSheetCol = 1 To 3

Debug.Print ColName(curSheetCol)
Next curSheetCol
End Sub

or use a collection...
Dim cColNames As Collection
Set cColNames=New Collection
cColNames.Add "ItemCode","ColName1"
cColNames.Add "Quantity","ColName2"
cColNames.Add "PriceQuote","ColName3"

Debug.Print cColNames.Item("ColName" & CStr(curSheetCol))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top