ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Enter formula in a macro (https://www.excelbanter.com/excel-programming/360240-enter-formula-macro.html)

Annette

Enter formula in a macro
 
I would like to have a macro when clicked on any cell, would run a formula,
but I can't find any examples of how to do this.

The formula is always in the same column referencing the same columns. (I
know I could copy and paste, but the formulas are different for different
items and I want to write a macro for each.)

=round(col c - row whatever / 55.12, 0)

Thanks!



davegb

Enter formula in a macro
 

Annette wrote:
I would like to have a macro when clicked on any cell, would run a formula,
but I can't find any examples of how to do this.

The formula is always in the same column referencing the same columns. (I
know I could copy and paste, but the formulas are different for different
items and I want to write a macro for each.)

=round(col c - row whatever / 55.12, 0)

Thanks!


Assuming the formula goes into cell A1 in the active workbook and
sheet, and that the row is described by a defined variable called
"whatever", try:

range("A1").formula = "=round(c:" & whatever & "/55.12, 0)"


Tom Ogilvy

Enter formula in a macro
 

ActiveCell.Formula = "=round(C" & activecell.row & "/ 55.12, 0)"

or
ActiveCell.FormulaR1C1 = "=Round(RC3/55.12,0)"

--
Regards,
Tom Ogilvy


"Annette" wrote:

I would like to have a macro when clicked on any cell, would run a formula,
but I can't find any examples of how to do this.

The formula is always in the same column referencing the same columns. (I
know I could copy and paste, but the formulas are different for different
items and I want to write a macro for each.)

=round(col c - row whatever / 55.12, 0)

Thanks!




Annette

Enter formula in a macro
 
Great ... this is exactly what I needed! And written so I can understand it
.... both ways.


"Tom Ogilvy" wrote in message
...

ActiveCell.Formula = "=round(C" & activecell.row & "/ 55.12, 0)"

or
ActiveCell.FormulaR1C1 = "=Round(RC3/55.12,0)"

--
Regards,
Tom Ogilvy


"Annette" wrote:

I would like to have a macro when clicked on any cell, would run a
formula,
but I can't find any examples of how to do this.

The formula is always in the same column referencing the same columns.
(I
know I could copy and paste, but the formulas are different for different
items and I want to write a macro for each.)

=round(col c - row whatever / 55.12, 0)

Thanks!







All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com