sn152
Member
Hi All,
I am trying to insert a formula in a dynamic range of cells using VBA.
Formula - =IF(D2="-",E2,IF(E2="-",D2,CONCATENATE(D2,"-",E2)))
I want to insert this formula in column P. That is from Range P2 till the last row in which data is available in column A.
I tried recording the macro (below is the code). But it is not working. Tried few other methods, but no luck.
Please help me here. Thanks!
I am trying to insert a formula in a dynamic range of cells using VBA.
Formula - =IF(D2="-",E2,IF(E2="-",D2,CONCATENATE(D2,"-",E2)))
I want to insert this formula in column P. That is from Range P2 till the last row in which data is available in column A.
I tried recording the macro (below is the code). But it is not working. Tried few other methods, but no luck.
Code:
Sub Macro3()
'
' Macro3 Macro
'
Range("P2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-12]=""-"",RC[-11],IF(RC[-11]=""-"",RC[-12],CONCATENATE(RC[-12],""-"",RC[-11])))"
Range("P2").Select
Selection.Copy
Range("O2").Select
Selection.End(xlDown).Select
Selection.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.End(xlUp).Select
Application.CutCopyMode = False
End Sub
Please help me here. Thanks!