I am just a beginner with VBA so pardon me in advance for the simple question.
I have a VBA that pastes the formula to columns that are non-contiguous.
Sub FillFormula()
Range("XET3").Formula = "=TRIM(RC[1])&TRIM(RC[2])&"",""&TRIM(RC[3])"
Range("XEU3").Formula = "=TEXT(RC4,""Mmm"")"
Range("XEV3").Formula = "=DAY(RC4)"
Range("XEW3").Formula = "=YEAR(RC4)"
Range("XEZ3").Formula = "=IF(TRIM(LEFT(RC[-1],4))=""9999"",""no"",""yes"")"
Range("XFA3").Formula = "=IF(RC[-1]=""yes"",(DATE((LEFT(RC[-2],4)),(MID(RC[-2],6,2)),(RIGHT(RC[-2],2))))-(DATE((LEFT(RC[-3],4)),(MID(RC[-3],6,2)),(RIGHT(RC[-3],2)))),"""")"
Range("XFB3").Formula = "'=IFERROR(IF(AND(XFA3>=30,XEZ3=""yes""),1,0),0)"
Range("XFD3").Formula = "'=TEXT((MONTH(D3)&""/""&DAY(D3)&""/""&YEAR(D3)),""Mmm"")&RIGHT(YEAR((MONTH(D3)&""/""&DAY(D3)&""/""&YEAR(D3))),2)"
End Sub
I need a VBA code that would drag down all these formula based on the last row of Column D.
I wrote it as:
Sub FillDown()
Dim lastRow As Long
lastRow = Range("D" & Rows.Count).End(xlUp).Row
Range("XET3").Copy
Range(Cells(3, 16374), Cells(lastRow, 16374)).PasteSpecial (xlPasteFormulas)
End Sub
But this would do it column by column. Is there a way to simplify this?
Thanks!
Bookmarks