Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default A simple question -- Evaluate()

Hi all,

I have the following code:

Sub test2()
Dim j As Integer
Dim varCol3 As Integer, varCol4 As Integer, varCol5 As Integer

varCol3 = 13
varCol4 = 14
varCol5 = 15

For j = 3 To 5
ActiveCell.Offset(0, j).Value = Evaluate("varCol" & Str(j))
Next j
End Sub

Why would evaluate() not evalute what I expect, i.e put th
corresponding values into the cells?

Thanks in advance

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default A simple question -- Evaluate()

It looks like you are trying to do the following:

Sub test()
Dim myvariable As String

myvariable = "example string"

MsgBox Evaluate("myvariable")
End Sub


It don't think it's not possible to get the value of a variable using a
string containing it's name.


What you could do is as follows:

Sub test2()
Dim j As Integer
Dim varCol3 As Integer, varCol4 As Integer, varCol5 As Integer

varCol3 = 13
varCol4 = 14
varCol5 = 15

For j = 3 To 5
With ActiveCell.Offset(0, j)
Select Case j
Case 3: .Value = varCol3
Case 4: .Value = varCol4
Case 5: .Value = varCol5
End Select
End With
Next j
End Sub


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


"kaon " wrote in message
...
Hi all,

I have the following code:

Sub test2()
Dim j As Integer
Dim varCol3 As Integer, varCol4 As Integer, varCol5 As Integer

varCol3 = 13
varCol4 = 14
varCol5 = 15

For j = 3 To 5
ActiveCell.Offset(0, j).Value = Evaluate("varCol" & Str(j))
Next j
End Sub

Why would evaluate() not evalute what I expect, i.e put the
corresponding values into the cells?

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default A simple question -- Evaluate()

Hi,

The simple answer is that Evaluate doesn't work like that :-(

The Evaluate function permits VBA to do what you might expect to do from an
XL cell. For example if cell A1 held 2 and A2 held 4 then
Evaluate("=A1+A2") would yield 6.

In effect Evaluate "passes back" to XL the calc. Sadly, XL knows nothing
about varCol3, varCol4 etc. as they sit in VBA-land.

Although Evaluate is a cunning function, it is one that is not commonly
used. Perhaps you could describe what you are trying to do?

One solution to your example would be:

Sub Test3()
dim i as integer

for i = 3 to 5
ActiveCell.Offset(0,i).Value = i + 10
next i
End Sub

Regards,

Peter Beach


"kaon " wrote in message
...
Hi all,

I have the following code:

Sub test2()
Dim j As Integer
Dim varCol3 As Integer, varCol4 As Integer, varCol5 As Integer

varCol3 = 13
varCol4 = 14
varCol5 = 15

For j = 3 To 5
ActiveCell.Offset(0, j).Value = Evaluate("varCol" & Str(j))
Next j
End Sub

Why would evaluate() not evalute what I expect, i.e put the
corresponding values into the cells?

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/



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
Simple question [email protected] New Users to Excel 4 March 24th 08 07:47 PM
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM
A simple question Ron de Bruin Excel Programming 0 July 25th 03 04:30 PM


All times are GMT +1. The time now is 02:35 PM.

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"