jalrs
Active Member
- Joined
- Apr 6, 2022
- Messages
- 300
- Office Version
- 365
- Platform
- Windows
Hello guys,
I'm trying to add a formulaR1C1 to my code but it's not working.
I'm doing this because I'm clearing used range contents firstly, to avoid double clicking, but it removes the excel formula. Therefore, I need to add the formula through the code by R1C1 way.
Happens it is not working. I did it by triggering macro recorder -> f2 -> enter -> disabling macro recorder as Joe4 taught me once.
both codes that the macro recorder gave me were:
I then adapted it (accordingly to the formulaR1C1 I have working on another module) as I want it to perform on whole column, starting from row 2, and not on a certain range:
Here is my code:
Any help is greatly appreciated
Thanks!
I'm trying to add a formulaR1C1 to my code but it's not working.
I'm doing this because I'm clearing used range contents firstly, to avoid double clicking, but it removes the excel formula. Therefore, I need to add the formula through the code by R1C1 way.
Happens it is not working. I did it by triggering macro recorder -> f2 -> enter -> disabling macro recorder as Joe4 taught me once.
both codes that the macro recorder gave me were:
VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveCell.FormulaR1C1 = _
"=IFERROR(IF(RC[-4]="""","""",VLOOKUP(RC4&RC5,'Matriz Áreas'!C1:C5,4,0)),""VALIDAR"")"
Range("H3").Select
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
Range("I2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(IF(RC[-1]="""","""",VLOOKUP(R[3]C4&R[3]C5,'Matriz Áreas'!C1:C5,5,0)),""VALIDAR"")"
Range("I3").Select
End Sub
I then adapted it (accordingly to the formulaR1C1 I have working on another module) as I want it to perform on whole column, starting from row 2, and not on a certain range:
Here is my code:
VBA Code:
Sub integrar()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wb As Workbook, ws As Worksheet
dim lr1 as long, lr2 as long
Set wb = ThisWorkbook
Set ws = wb.Worksheets("TFDB")
ws.UsedRange.Offset(1).ClearContents
Call integrarf1
Call integrarf2
lr1 = ws.cells(rows.count, "D").End(xlup).Row
lr2 = ws.cells(rows.count, "H").End(xlup).Row
if lr1 > 1
Range("H2:H" & lr1).FormulaR1C1 = _
"=IFERROR(IF(RC[-1]="""","""",VLOOKUP(RC[-1],Matriz Áreas!C[-1]:C[-5],4,0)),""VALIDAR"")"
End If
if lr2 > 1
Range("H2:H" & lr2).FormulaR1C1 = _
"=IFERROR(IF(RC[-4]="""","""",VLOOKUP(RC[-4],Matriz Áreas!C[-1]:C[-5],5,0)),""VALIDAR"")"
end if
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Any help is greatly appreciated
Thanks!