Paradox
Paradox

Reputation: 4556

Excel formula to VBA code

How would I go about turning the excel formula =B4/B5 into vba code? So far, this is my code which does not work of course:

ActiveCell.FormulaR1C1 = "=B4/B5"

As you can tell, I am not very familiar with R1C1. If needed, I have created a function Col_Letter() which takes a number and returns the letter of the corresponding column. Any help would be greatly appreciated!

Upvotes: 0

Views: 187

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

As pointed out in the comments by @siddarth you are looking for:

ActiveCell.Formula = "=B4/B5"

If you are in a hurry and just need to make the macro work, a compromise on code readability may be acceptable. In that case you could do the following:

  1. Start recording a macro
  2. Do EXACTLY what you need to do
  3. Stop recording and extract the line from the macro code

Note that this will work for nearly everything, but may lead to somewhat confusing code.

Upvotes: 3

Related Questions