|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to write a macro for inserting a formula in an Excel cell such that its components be p
I have written a macro, in a part of it, I want to insert a formula in an Excel cell which its components are parameters not texts. But when running the code, the excel encounters an error saying “Run time error 1004,Application defined or Object defined error". Can anybody Guides me on this issue? (the part of Macro with this problem is as follow. For example, When I am in C5, when running the macro, I expect to see the formula =C5+C6 in C1 )
Sub insertformula() cell01 = ActiveCell.Address(0, 0) ActiveCell.Offset(1, 0).Activate cell02 = ActiveCell.Address(0, 0) range("c1").Value = "=&cell01& + &cell02&" End Sub Last edited by soroush.kalantari; 04-17-2022 at 07:59 PM. |
#2
|
||||
|
||||
Code:
Sub insertformula() cell01 = ActiveCell.Address(0, 0) cell02 = ActiveCell.Offset(1, 0).Address(0, 0) Range("c1").Formula = "=" & cell01 & "+" & cell02 End Sub |
#3
|
|||
|
|||
Thank you very much. Your reply solved the problem.
|
Tags |
formula, parameters |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
HOW TO write a macro for dynamic relative named ranges in Excel? | soroush.kalantari | Excel Programming | 7 | 01-28-2022 09:35 PM |
Macro to write bold and unformatted text in a single cell | Snoorelax | Word VBA | 2 | 06-27-2018 06:24 PM |
Macro to copy formula from one cell to another | anwar | Excel Programming | 1 | 04-25-2014 08:27 PM |
Is it possible to write down a number starting with zero in excel cell? | Rahmat_uk20 | Excel | 3 | 06-08-2012 02:26 AM |
How can I write the following (whole) formula in a single cell? | Learner7 | Excel | 1 | 07-19-2010 10:06 AM |