(urgent:)VBA coding.....Selection.Formula

alfee

New Member
Joined
Mar 5, 2009
Messages
5
I am appreciated if there is someone out there can give me a hand on this!

I am trying to write an VBA in excel; here is the coding:

Sheet1.Cells(5, 5).Select *it will bring me to the cell E5
Selection.Formula = "=A1" *it will enter a formula: "=A1" in the E5

My question is how can I enter a coding like above in cell E5 which gives me an addition of E4 and D5 (ie. to add the cell above my starting postion and the cell on the left). But the command: Selection.Formula="=E4+D5" could not help as I need the formula to be using 'relative address (ie. adding the cell above me and the cell on my left)'' instead of "absolute address (ie. E4+D5)" so that I can use the command on other cell.
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Colin Legg

MrExcel MVP
Joined
Feb 28, 2008
Messages
3,497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi alfee,

See if this works for you:

Code:
 Sheet1.Cells(5, 5).FormulaR1C1 = "=R[-1]C+RC[-1]"
 
Upvote 0

Forum statistics

Threads
1,191,371
Messages
5,986,264
Members
440,015
Latest member
knijgh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top