Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.Evaluate vs. Activesheet.Evaluate

Tags:

excel

vba

I was reading this thread A custom find function and this was stated

Interesting result. Note that Evaluate is same as Application.Evaluate and takes roughly twice as long as Activesheet.Evaluate – chris neilsen

Should one always use Activesheet.Evaluate in place of Application.Evaluate?

Thanks

like image 956
xyz Avatar asked Oct 01 '22 12:10

xyz


1 Answers

I don't know if you should, but it looks like you can. For example these all work:

Activesheet.Evaluate("2")

Activesheet.Evaluate("Sheet1!A1+Sheet2!A1")

Activesheet.Evaluate("SUM([Book1]Sheet1!A1,[Book1]Sheet2!A1,[Book2]Sheet1!A1,[Book2]Sheet2!A1)")

The first case is worksheet-agnostic, and it returns the correct result in the Immediate window.

The second refers to two sheets and also returns the correct result. As does the third, which refers to two different workbooks.

The obvious caveat is to always fully qualify any worksheet or workbook references.

like image 150
Doug Glancy Avatar answered Oct 12 '22 12:10

Doug Glancy