Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2022, 04:14 AM
soroush.kalantari soroush.kalantari is offline How to write a macro for inserting a formula in an Excel cell such that its components be p Windows 10 How to write a macro for inserting a formula in an Excel cell such that its components be p Office 2016
Competent Performer
How to write a macro for inserting a formula in an Excel cell such that its components be p
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 04-18-2022, 06:03 AM
p45cal's Avatar
p45cal p45cal is offline How to write a macro for inserting a formula in an Excel cell such that its components be p Windows 10 How to write a macro for inserting a formula in an Excel cell such that its components be p Office 2019
Expert
 
Join Date: Apr 2014
Posts: 863
p45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant future
Default

Code:
Sub insertformula()
cell01 = ActiveCell.Address(0, 0)
cell02 = ActiveCell.Offset(1, 0).Address(0, 0)
Range("c1").Formula = "=" & cell01 & "+" & cell02
End Sub
Reply With Quote
  #3  
Old 04-18-2022, 07:50 PM
soroush.kalantari soroush.kalantari is offline How to write a macro for inserting a formula in an Excel cell such that its components be p Windows 10 How to write a macro for inserting a formula in an Excel cell such that its components be p Office 2016
Competent Performer
How to write a macro for inserting a formula in an Excel cell such that its components be p
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by p45cal View Post
Code:
Sub insertformula()
cell01 = ActiveCell.Address(0, 0)
cell02 = ActiveCell.Offset(1, 0).Address(0, 0)
Range("c1").Formula = "=" & cell01 & "+" & cell02
End Sub
Thank you very much. Your reply solved the problem.
Reply With Quote
Reply

Tags
formula, parameters

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a macro for inserting a formula in an Excel cell such that its components be p HOW TO write a macro for dynamic relative named ranges in Excel? soroush.kalantari Excel Programming 7 01-28-2022 09:35 PM
How to write a macro for inserting a formula in an Excel cell such that its components be p 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 to write a macro for inserting a formula in an Excel cell such that its components be p How can I write the following (whole) formula in a single cell? Learner7 Excel 1 07-19-2010 10:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft