ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using a macro to do a calculation (https://www.excelbanter.com/excel-programming/396444-using-macro-do-calculation.html)

bhrosey via OfficeKB.com

Using a macro to do a calculation
 
I have the following macro, but how do make it so it will do the calculation
for any cell I select instead of just the original cell?

Range("F14").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]=""nv71pull"",(RC[-1]/192),(RC[-1]
/150))"

Thanks in advance for the help

Bill R.
God Bless

--
John 3:16 "For God so loved the world that He gave His only begotten Son, so
that whoever believes in Him shall not parish, but have eternal life"

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1


JW[_2_]

Using a macro to do a calculation
 
Just take out the Range("F14").Select statement and the formula will
be placed in the active cell. If you need to loop through a range and
pug in that formula, look at using a For...Next loop.

bhrosey via OfficeKB.com wrote:
I have the following macro, but how do make it so it will do the calculation
for any cell I select instead of just the original cell?

Range("F14").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]=""nv71pull"",(RC[-1]/192),(RC[-1]
/150))"

Thanks in advance for the help

Bill R.
God Bless

--
John 3:16 "For God so loved the world that He gave His only begotten Son, so
that whoever believes in Him shall not parish, but have eternal life"

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1



Gary''s Student

Using a macro to do a calculation
 
Just remove the:
Range("F14").Select

without this line, the formula will go in the currently selected cell
--
Gary''s Student - gsnu200740


"bhrosey via OfficeKB.com" wrote:

I have the following macro, but how do make it so it will do the calculation
for any cell I select instead of just the original cell?

Range("F14").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]=""nv71pull"",(RC[-1]/192),(RC[-1]
/150))"

Thanks in advance for the help

Bill R.
God Bless

--
John 3:16 "For God so loved the world that He gave His only begotten Son, so
that whoever believes in Him shall not parish, but have eternal life"

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1



bhrosey via OfficeKB.com

Using a macro to do a calculation
 
How would I do this for a group of cells? For example: I want to highlight
cells F14 : F26 and perform the same calculation in each of those cells.

JW wrote:
Just take out the Range("F14").Select statement and the formula will
be placed in the active cell. If you need to loop through a range and
pug in that formula, look at using a For...Next loop.

I have the following macro, but how do make it so it will do the calculation
for any cell I select instead of just the original cell?

[quoted text clipped - 14 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1


--
John 3:16 "For God so loved the world that He gave His only begotten Son, so
that whoever believes in Him shall not parish, but have eternal life"

Message posted via http://www.officekb.com


bhrosey via OfficeKB.com

Using a macro to do a calculation
 
It's only doing the calculation for first cell of the highlighted group.
Here is the way my code looks now.

Sub calculatepallets()
ActiveCell.FormulaR1C1 = "=IF(RC[-4]=""nv71pull"",(RC[-1]/192),(RC[-1]
/150))"
End Sub

Thanks

Gary''s Student wrote:
Just remove the:
Range("F14").Select

without this line, the formula will go in the currently selected cell
I have the following macro, but how do make it so it will do the calculation
for any cell I select instead of just the original cell?

[quoted text clipped - 7 lines]
Bill R.
God Bless


--
John 3:16 "For God so loved the world that He gave His only begotten Son, so
that whoever believes in Him shall not parish, but have eternal life"

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200709/1



All times are GMT +1. The time now is 12:09 AM.

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