Use the R1C1 property

Asked

Viewed 11,000 times

3

I want to use the property Range.Formula R1C1 in a check copy form for automatic filling of cheque nominal. How could I use this property for this purpose?

I found a code described as follows:

Sub Para()
'
' Para Macro
' Macro gravada em 4/9/2006 por Fundação  Fé e Alegria
'
'
Range("D7:J14").Select

ActiveCell.FormulaR1C1 = "=R[-9]C"

Range("D15:

But I didn’t understand.

1 answer

2

Activecell.Formular1c1 is for you to write to the selected cell. If you do:

Range("D7").Select
ActiveCell.FormulaR1C1 = "abc"

macro selects cell D7 and writes abc in it.

In your example you selected several rows and columns, however you only wrote in the first of them, the D7.

Its macro makes the cell content a formula that simply replicates the content of another cell, because of the = followed by a relative position. The relative position you wrote was R[-9]C which says that the address of the other cell is 9 lines and less than the current one, in the same column. R is an abbreviation of ROW, meaning line. C is an abbreviation of COLUMN meaning column.

9 less lines will likely cause unwanted behavior, since you are on line 7.

Correctly calculate the relative value of cell D7 and replace it in your macro. Also, you can change the Range("D7:J14").Select for Range("D7").Select, since it’s not making a difference. If your intention is to write to all fields in this range, redo your macro to copy cell by cell. Selecting a range has other utilities such as merging such cells.

Another example of relative cell calculation: R[-1]C[-2], refers to one row less and two columns less.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.