Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Dynamic Variables

How do you create a variable variable? Consider this code
dim x as strin
x = "Whatever
the character 'x' may be different (for later use) and needs to be dynamically defined in code from a cell value

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Dynamic Variables

For what purpose? In most cases you wont need to do that.


It is possible. I know you can dynamically alter the code in a module using
VBComponent object. I have some examples on my website - but as I said, I
think it's unnecessary. Just tell us the reason behind it. Perhaps there's a
better way.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Lawlera" wrote in message
...
How do you create a variable variable? Consider this code:
dim x as string
x = "Whatever"
the character 'x' may be different (for later use) and needs to be

dynamically defined in code from a cell value.

TIA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Dynamic Variables

Hi Rob

Just for the sake of it if I'm honest. The idea was born out of need to loop through 100 or so sheets and returning a value for each one after a series of calculations, hence the variable could have a letter and the sheets number added


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Dynamic Variables

Hi
for this use an array variable. e.g. try something like
the following:


Sub get_sheetnames()
Dim sname()
Dim wks_index
Dim wks_count
wks_count = ActiveWorkbook.Worksheets.Count
ReDim sname(1 To wks_count)

For wks_index = 1 To wks_count
sname(wks_index) = ActiveWorkbook.Worksheets
(wks_index).Name
Next

For wks_index = 1 To wks_count
MsgBox sname(wks_index)
Next
End Sub

-----Original Message-----
Hi Rob,

Just for the sake of it if I'm honest. The idea was born

out of need to loop through 100 or so sheets and returning
a value for each one after a series of calculations, hence
the variable could have a letter and the sheets number
added.


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Dynamic Variables

It sounds like you want a dynamic array.

Sub test()
Dim arr()
Dim i As Long

ReDim arr(100)

For i = 1 To 100
arr(i) = i * 10
Next

For i = 1 To 100
Debug.Print arr(i)
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Lawlera" wrote in message
...
Hi Rob,

Just for the sake of it if I'm honest. The idea was born out of need to

loop through 100 or so sheets and returning a value for each one after a
series of calculations, hence the variable could have a letter and the
sheets number added.






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
Lookup Question with multiple dynamic variables Robin Excel Worksheet Functions 14 June 12th 08 09:40 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 2 January 15th 05 05:03 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 1 January 15th 05 02:23 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 0 January 15th 05 02:00 PM
dynamic variables Christian Lehmann Excel Programming 3 October 19th 03 12:13 PM


All times are GMT +1. The time now is 06:34 AM.

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

About Us

"It's about Microsoft Excel"