Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel & VBA: Skip calculating formula in Macro

Tags:

excel

vba

I'm having a rather simple issue with Macro. In it, I assign a formula to a cell. I would like it not to calculate it at first and do calculation only after some other part of Macro is finished. I thought I would do something like this:

Application.Calculation = xlCalculationManual
Cells(StartRow, 4 + i).Formula = "FORMULA"
...
Application.Calculation = xlCalculationAutomatic

But that doesn't work. It stops automatic calculations, but not for that cell - it still performs the calculation right after I assign the formula. Is there a way to skip it?

To clarify the exact prupose of this: in my actual code I'm assigning a formula to a group of cells in a cycle. Everytime I assign it to one cell - it calculates it. I figured if I will first assign them all and then do the calculation - it would be faster. As a matter of fact it is. So instead of assigning it in a cycle, I assign it to the first cell and then do autofill. Autofilled formulas wait until I enable automatic calculation and I get a much faster macro. However, the initial assignemnt is still calculated which makes macro almost twice as slow.

like image 639
waterplea Avatar asked Aug 24 '13 12:08

waterplea


People also ask

What's Excel used for?

Microsoft Excel enables users to format, organize and calculate data in a spreadsheet. By organizing data using software like Excel, data analysts and other users can make information easier to view as data is added or changed. Excel contains a large number of boxes called cells that are ordered in rows and columns.

Is basic Excel free?

Using Microsoft Excel and other core Office programs is free via the web, and all you'll need is a Microsoft account. Head over to Office.com and click 'Sign in' to enter your details.

What is Excel basic formula?

1. Formulas. In Excel, a formula is an expression that operates on values in a range of cells or a cell. For example, =A1+A2+A3, which finds the sum of the range of values from cell A1 to cell A3.

Is sheets better than Excel?

Both Google Sheets and Excel are good to use. They both have some unique features. If you want to collaborate on data, opt for Google Sheets. However, for calculations and analysis, Excel is a better application.


1 Answers

  1. place the formula in the cell with a prefix character
  2. continue the macro
  3. "activate" the formula

for example:

Sub dural()
    With Range("A1")
        .Value = "'=1+2"
        MsgBox " "
        .Value = .Value
    End With
End Sub
like image 101
Gary's Student Avatar answered Sep 20 '22 19:09

Gary's Student