coocooworld
New Member
- Joined
- Aug 19, 2011
- Messages
- 7
Hello Experts,
I'm am trying to optimize my vba codes and am running into a road block; I'm pretty sure there is a solution out there but I haven't been able to find it for days.
I am trying to apply an equation to a ranges of cells without using a loop. I have been successful at using the loop to apply the equation; the problem is, it is a for loop and it is taking a very long time to go through all the cells. I have thousands and thousands of numerical value that I would like to apply an equation to. Here is the code I am trying to optimize:
Is there a way to apply "=eval" to every cells without using a for loop?
For example, I have this:
3_______5_______2
4_______1_______6
2_______3_______2
Let's say "eval" will add 1 to it (actual equation is a lot more complicated), so I will get this
4_______6_______3
5_______1_______7
3_______4_______4
It would be easier to apply an equation to all the cells rather then use a for loop. So I want to do this:
=eval(3)_______=eval(5)_______=eval(2)
=eval(4)_______=eval(1)_______=eval(6)
=eval(2)_______=eval(3)_______=eval(2)
Please help. Your opinions are greatly appreciated. thanks
I'm am trying to optimize my vba codes and am running into a road block; I'm pretty sure there is a solution out there but I haven't been able to find it for days.
I am trying to apply an equation to a ranges of cells without using a loop. I have been successful at using the loop to apply the equation; the problem is, it is a for loop and it is taking a very long time to go through all the cells. I have thousands and thousands of numerical value that I would like to apply an equation to. Here is the code I am trying to optimize:
Code:
dim mycell as range
dim lastcol as string
dim lastrow as integer
......
.....
For Each mycell In Workbooks(xWb).Worksheets(2).Range("A1:" & lastcol & lastrow)
mycell.Value = eval(mycell.Value)
Next
Is there a way to apply "=eval" to every cells without using a for loop?
For example, I have this:
3_______5_______2
4_______1_______6
2_______3_______2
Let's say "eval" will add 1 to it (actual equation is a lot more complicated), so I will get this
4_______6_______3
5_______1_______7
3_______4_______4
It would be easier to apply an equation to all the cells rather then use a for loop. So I want to do this:
=eval(3)_______=eval(5)_______=eval(2)
=eval(4)_______=eval(1)_______=eval(6)
=eval(2)_______=eval(3)_______=eval(2)
Please help. Your opinions are greatly appreciated. thanks