Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default concatenating strings to call a variable

I have a workbook for looking up data that was pretty specialized when
I wrote it and I am trying to generalize it a little bit for other
uses.

I would like to concatenate 2 strings to make the name a variable that
is used in a range call. Complicated enough?

Currently the code is set up to read from a specific column.
"WT_Config_Col" is a string variable that is the Column of a type of
data. I would like to be able to pass "WT" to the routine below and
concatenate that string with "_Config_Col" and have that read as the
varaiable WT_Config_Col.

Sub RunComparisonWTCellCopy(rowcount)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(WT_Config_Col
&
activecell.Row).Value 'copy config
end sub

I suppose it might look something like this:

dim DataSource as string
DataSource = "WT"

Sub RunComparisonWTCellCopy(rowcount, DataSource)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(DataSource &
"_Config_Col" & activecell.Row).Value 'copy config
end sub

Unfortunately it will not treat 'DataSource & "_Config_Col"' as a
variable whose value is simply a string (a, b, c...)

In essence I want to concatenate 2 text strings and have excel
recognize that as a variable name and use it's variables value.

thank you for your help,
FRB
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default concatenating strings to call a variable

VB/VBA doesn't support that directly that I am aware of.

Maybe use a case statement.

--
Regards,
Tom Ogilvy

"Frank Brown" wrote in message
om...
I have a workbook for looking up data that was pretty specialized when
I wrote it and I am trying to generalize it a little bit for other
uses.

I would like to concatenate 2 strings to make the name a variable that
is used in a range call. Complicated enough?

Currently the code is set up to read from a specific column.
"WT_Config_Col" is a string variable that is the Column of a type of
data. I would like to be able to pass "WT" to the routine below and
concatenate that string with "_Config_Col" and have that read as the
varaiable WT_Config_Col.

Sub RunComparisonWTCellCopy(rowcount)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(WT_Config_Col
&
activecell.Row).Value 'copy config
end sub

I suppose it might look something like this:

dim DataSource as string
DataSource = "WT"

Sub RunComparisonWTCellCopy(rowcount, DataSource)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(DataSource &
"_Config_Col" & activecell.Row).Value 'copy config
end sub

Unfortunately it will not treat 'DataSource & "_Config_Col"' as a
variable whose value is simply a string (a, b, c...)

In essence I want to concatenate 2 text strings and have excel
recognize that as a variable name and use it's variables value.

thank you for your help,
FRB



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default concatenating strings to call a variable

Thanks Tom. Specifically for this reply but also for your many other
posts that have solved lots of other VBA problems.

I sort of thought that might be the case and I have work arounds but I
was hoping to streamline some code.

Take Care,
Frank


"Tom Ogilvy" wrote in message ...
VB/VBA doesn't support that directly that I am aware of.

Maybe use a case statement.

--
Regards,
Tom Ogilvy

"Frank Brown" wrote in message
om...
I have a workbook for looking up data that was pretty specialized when
I wrote it and I am trying to generalize it a little bit for other
uses.

I would like to concatenate 2 strings to make the name a variable that
is used in a range call. Complicated enough?

Currently the code is set up to read from a specific column.
"WT_Config_Col" is a string variable that is the Column of a type of
data. I would like to be able to pass "WT" to the routine below and
concatenate that string with "_Config_Col" and have that read as the
varaiable WT_Config_Col.

Sub RunComparisonWTCellCopy(rowcount)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(WT_Config_Col
&
activecell.Row).Value 'copy config
end sub

I suppose it might look something like this:

dim DataSource as string
DataSource = "WT"

Sub RunComparisonWTCellCopy(rowcount, DataSource)
Worksheets("run comparisons").Cells(rowcount, 1) = Range(DataSource &
"_Config_Col" & activecell.Row).Value 'copy config
end sub

Unfortunately it will not treat 'DataSource & "_Config_Col"' as a
variable whose value is simply a string (a, b, c...)

In essence I want to concatenate 2 text strings and have excel
recognize that as a variable name and use it's variables value.

thank you for your help,
FRB

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenating two variable fields into a static length text field Young Programmer Lad Excel Worksheet Functions 2 April 17th 09 05:39 PM
Concatenating two text strings, formula is right, cell output is w Bojamin Excel Worksheet Functions 3 March 3rd 09 08:08 PM
How do I start new line when concatenating text strings in excel? Max Excel Discussion (Misc queries) 2 January 26th 06 05:48 PM
Not sure of what to call it accept (Un - concatenating) Tom Excel Programming 1 April 12th 04 02:45 PM
can I call a procedure using a variable Santiago Gomez Excel Programming 8 December 24th 03 09:08 PM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"