ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Evaluate does not work (https://www.excelbanter.com/excel-programming/444025-evaluate-does-not-work.html)

Slim Slender[_3_]

Evaluate does not work
 
numRows = Selection.CurrentRegion.Rows.Count
myRow = 2 'start below header
Do
For myColumn = 4 To 11 '
With Worksheets("Sheet1")
myArray(1) = .Cells(myRow, 1)
Age = .Cells(myRow, 2)
myArray(2) =
Evaluate("=IF(TRUNC(Age)=0,"""",TRUNC(Age)&"" y,"")&"" "" &ROUND(((Age-
TRUNC(Age))*365)/30,0)&"" mo.""")
myArray(3) = .Cells(myRow, 3)
End With
With Worksheets("Sheet2")
i = i + 1
.Range(.Cells(i, 1), .Cells(i, 3)) = myArray
End With
Next myColumn
myRow = myRow + 1
Loop Until Cells(myRow, 1).Row numRows

The code above runs fine and works in every way reading some junk off
one sheet and writing it to another. The only problem is the
myArray(2) = Evaluate. On the first pass, Age = 37.05 and myArray(2)
correctly evaluates to 37 y, 1 mo. In the next loop Age changes to
17.91 but myArray(2) stays 37 y, 1 mo. and remains that from then on
regardless of what Age is.


All times are GMT +1. The time now is 01:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com