whitey1987
New Member
- Joined
- Jun 11, 2011
- Messages
- 7
Hi everyone,
Hoping someone can help me with this. I've created a Macro to input an IF formula into my spreadsheet. The number of rows in the spreadsheet changes on a regular basis. So I would like to adapt my macro so that the formula fills to the last row of data each time it is run.
Can anyone please adapt the code I have below?
Sub Macro1()
'
' Macro1 Macro
' Inserts If formula.
'
'
Columns("D:D").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-2]=""FGH"",RC[1]=""123""),RC[-2]&RC[1],IF(AND(RC[-2]=""FGH"",RC[1]<>""123""),RC[-2],IF(AND(RC[1]=""123"",OR(RC[-2]=""IJK"",RC[-2]=""ABC"",RC[-2]=""CDE"")),RC[-2]&RC[1],RC[-2]&RC[-1])))"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D880")
Range("D2:D880").Select
Range("A1").Select
End Sub
Thank you in advance for any help you can give.
Hoping someone can help me with this. I've created a Macro to input an IF formula into my spreadsheet. The number of rows in the spreadsheet changes on a regular basis. So I would like to adapt my macro so that the formula fills to the last row of data each time it is run.
Can anyone please adapt the code I have below?
Sub Macro1()
'
' Macro1 Macro
' Inserts If formula.
'
'
Columns("D:D").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-2]=""FGH"",RC[1]=""123""),RC[-2]&RC[1],IF(AND(RC[-2]=""FGH"",RC[1]<>""123""),RC[-2],IF(AND(RC[1]=""123"",OR(RC[-2]=""IJK"",RC[-2]=""ABC"",RC[-2]=""CDE"")),RC[-2]&RC[1],RC[-2]&RC[-1])))"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D880")
Range("D2:D880").Select
Range("A1").Select
End Sub
Thank you in advance for any help you can give.