R1C1 variable reference

Willriver

New Member
Joined
Mar 24, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi all, I really need your help.
But before that i'm gonna try to explain your what i'm trying to do .
My program is divided in 2 parts.
The first one will find all the 0 in the 2nd row, and it actually works perfectly.
In the second part , the program will find if the value of the second row is different than the value of the 12th row and if it's different it gonna add a new column, but the problem starts here , i need to put a formula ( for example : S13/$S$12*$S$2 , this example is for the columns that the image shows).

I'm trying to use R1C1 but the program shows me an error.

I'm gonna attach two pictures, and the program for a better understand.

And thank you so much

VBA Code:
Sub Prueba1()
Dim a As Integer, b As Integer, i As Integer, j As Integer, c As Integer, f As Integer
x = Range("R2").CurrentRegion.Columns.Count
a = 2
b = 12
c = 13

i = 18
    For i = i To x
        If Cells(a, i) = 0 Then
    Cells(a, i).EntireColumn.Delete
    End If
    
    Next
j = 18
    For j = j To x
    If Cells(a, j) <> Cells(b, j) Then
    f = j + 1
    Cells(c, f).EntireColumn.Insert
    Cells(c, f).FormulaR1C1 = "=(RC[-1])/R " & b & "C19"" * R " & a & "C19""
    End If
   
Next
End Sub

WhatsApp Image 2021-03-24 at 4.26.10 PM-min.jpeg

WhatsApp Image 2021-03-24 at 6.04.44 PM-min.jpeg
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi & welcome to MrExcel.
How about
VBA Code:
Cells(c, f).FormulaR1C1 = "=RC[-1]/R " & b & "C19 * R " & a & "C19"
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Cells(c, f).FormulaR1C1 = "=RC[-1]/R " & b & "C19 * R " & a & "C19"
Thanks for your answer , but unfortunately it shows me another error
1616686093809.png

Do you have an idea of how to solve that ?
 
Upvote 0
Try
VBA Code:
    Cells(c, f).FormulaR1C1 = "=RC[-1]/R" & b & "C19 * R" & a & "C19"
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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
Back
Top