#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Macro Relative Cells

Hi Guys.

Ok i'll try and explain this as simply as i can.

I want to create an expenses sheet which allocates the net amount to
individual cells depending on which cell is highlighted, by clicking a button.

So in cell B10 i put my gross amount = 100.00
C10 works out the VAT for me = 14.89

Now the user highlights the cell (in different columns) under the
appropriate heading eg. 'Petrol' and clicks the button at the top of the
sheet which automatically puts 85.11 in the highlighted cell.

Sounds simple.

I have created the button and i have created the Macro:
ActiveCell = "=B10-C10"

My question is, how can i make the macro formula relative to which cell i
have highlighted?

At present everytime i click it obviously just works out B10 - C10! Say i
went onto the next item in the list and had my amounts in B11 and C11, how
can i make the macro relative to the next row down?

Thanks for your time.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default Macro Relative Cells

Using an R1C1 formula is the way to do it:

ActiveCell.FormulaR1C1 = "=RC2-RC3"

Regards,
Per

"Bazy2k" skrev i meddelelsen
...
Hi Guys.

Ok i'll try and explain this as simply as i can.

I want to create an expenses sheet which allocates the net amount to
individual cells depending on which cell is highlighted, by clicking a
button.

So in cell B10 i put my gross amount = 100.00
C10 works out the VAT for me = 14.89

Now the user highlights the cell (in different columns) under the
appropriate heading eg. 'Petrol' and clicks the button at the top of the
sheet which automatically puts 85.11 in the highlighted cell.

Sounds simple.

I have created the button and i have created the Macro:
ActiveCell = "=B10-C10"

My question is, how can i make the macro formula relative to which cell i
have highlighted?

At present everytime i click it obviously just works out B10 - C10! Say i
went onto the next item in the list and had my amounts in B11 and C11, how
can i make the macro relative to the next row down?

Thanks for your time.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Macro Relative Cells

One way...

With ActiveCell
.Formula = "=B" & .Row & "-C" & .Row
End With
--
HTH...

Jim Thomlinson


"Bazy2k" wrote:

Hi Guys.

Ok i'll try and explain this as simply as i can.

I want to create an expenses sheet which allocates the net amount to
individual cells depending on which cell is highlighted, by clicking a button.

So in cell B10 i put my gross amount = 100.00
C10 works out the VAT for me = 14.89

Now the user highlights the cell (in different columns) under the
appropriate heading eg. 'Petrol' and clicks the button at the top of the
sheet which automatically puts 85.11 in the highlighted cell.

Sounds simple.

I have created the button and i have created the Macro:
ActiveCell = "=B10-C10"

My question is, how can i make the macro formula relative to which cell i
have highlighted?

At present everytime i click it obviously just works out B10 - C10! Say i
went onto the next item in the list and had my amounts in B11 and C11, how
can i make the macro relative to the next row down?

Thanks for your time.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Macro Relative Cells

PERFECT!!!

Thankyou for your speedy response!!

"Per Jessen" wrote:

Using an R1C1 formula is the way to do it:

ActiveCell.FormulaR1C1 = "=RC2-RC3"

Regards,
Per

"Bazy2k" skrev i meddelelsen
...
Hi Guys.

Ok i'll try and explain this as simply as i can.

I want to create an expenses sheet which allocates the net amount to
individual cells depending on which cell is highlighted, by clicking a
button.

So in cell B10 i put my gross amount = 100.00
C10 works out the VAT for me = 14.89

Now the user highlights the cell (in different columns) under the
appropriate heading eg. 'Petrol' and clicks the button at the top of the
sheet which automatically puts 85.11 in the highlighted cell.

Sounds simple.

I have created the button and i have created the Macro:
ActiveCell = "=B10-C10"

My question is, how can i make the macro formula relative to which cell i
have highlighted?

At present everytime i click it obviously just works out B10 - C10! Say i
went onto the next item in the list and had my amounts in B11 and C11, how
can i make the macro relative to the next row down?

Thanks for your time.


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Relative Macro DanP Excel Discussion (Misc queries) 6 March 17th 09 02:58 PM
relative value in macro Janett Excel Discussion (Misc queries) 2 April 4th 06 05:42 PM
Relative cells in macro - and pasting a formula too! Excel Discussion (Misc queries) 3 February 23rd 06 02:46 PM
macro relative referencing harriet Excel Discussion (Misc queries) 5 February 15th 05 01:40 PM
Relative Macro Help on Keystrokes Neal Zimm Excel Discussion (Misc queries) 9 December 15th 04 12:31 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"