maverick688
New Member
- Joined
- Feb 17, 2025
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi Everyone I am fairly new to vba. I have a macro that I am trying to input a formula then fill down. I have tried various examples below and i have found a workable answer example 4 works and was done by recording and slightly adjusting the VBA
Each of the other examples also work if I try it on its own, in a standalone macro but when I add them onto the end of a bigger macro the first 3 don't work .
examples 1 and 2 just deletes the header cell in the cell above and doesn't copy down, example 3 copies the header cell in row above and doesn't copy down i have declared the variables the same on them all.
I am just wondering if i am doing something wrong and why they work on their own but not part of the bigger macro.
1)
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("C2").FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
Range("C2").AutoFill Destination:=Range("C2:C" & LastRow)
2)
Range("C2:C" & LastRow).FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
3)
Range("G2").FormulaR1C1 = "=IF(RC[-4]=""Stock"",""Stock"","""")"
Range("G2:G" & LastRow).FillDown
4)Works but
Range("C2").FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
Range("C2").Copy
Range("D2").End(xlDown).Offset(0, -1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Each of the other examples also work if I try it on its own, in a standalone macro but when I add them onto the end of a bigger macro the first 3 don't work .
examples 1 and 2 just deletes the header cell in the cell above and doesn't copy down, example 3 copies the header cell in row above and doesn't copy down i have declared the variables the same on them all.
I am just wondering if i am doing something wrong and why they work on their own but not part of the bigger macro.
1)
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("C2").FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
Range("C2").AutoFill Destination:=Range("C2:C" & LastRow)
2)
Range("C2:C" & LastRow).FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
3)
Range("G2").FormulaR1C1 = "=IF(RC[-4]=""Stock"",""Stock"","""")"
Range("G2:G" & LastRow).FillDown
4)Works but
Range("C2").FormulaR1C1 = "=IF(RC[14]=""294547"",""Fire"",IF(RC[-1]="""","""",""Stock""))"
Range("C2").Copy
Range("D2").End(xlDown).Offset(0, -1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste