jaeremata
New Member
- Joined
- Jan 20, 2021
- Messages
- 24
- Office Version
- 2019
- 2016
- Platform
- Windows
Hi everyone! Hope everyone is doing great. I need your help regarding with my code. What it do is to automatically populate the column AJ - AO with the formula. But it's weird because it goes in the middle instead on the row. If you can see the SS, it goes in the middle but it should start on row 3. Can anyone help and correct what I need to do with my code.
VBA Code:
Sub Populate_Formulas()
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Dim lrow As Long
Dim usedRows As Long
Dim WS As Worksheet
Worksheets("List").Select
Set WS = ThisWorkbook.Worksheets("List")
'-------------------------Find number of lines with NC data
usedRows = WS.Cells(WS.Rows.Count, "G").End(xlUp).Row
lrow = Cells(Rows.Count, "AI").End(xlUp).Row
lrow = lrow + 1
'-------------------------Fill the formulas
Cells(lrow, "AJ").FormulaR1C1 = "=IF(RC[-9]=""No"","""",IF(RC[-4]="""",""On-Going"",IF(RC[-13]<>"""",IF(RC[-7]<>"""",NETWORKDAYS(RC[-7],RC[-4])-1,NETWORKDAYS(RC[-13],RC[-4])-1),"""")))"
Cells(lrow, "AK").FormulaR1C1 = "=IF(RC[-10]=""No"","""",IF(RC[-26]-RC[-27]<0,""On going"",NETWORKDAYS(RC[-27],RC[-26])-1))"
Cells(lrow, "AL").FormulaR1C1 = "=IF(RC[-11]=""No"","""",IF(OR(RC[-24]<>""EX"",RC[-10]="""",RC[-15]=""""),"""",IF((NETWORKDAYS(RC[-15],RC[-10])-1)<=2,""On-Time"",""Not"")))"
Cells(lrow, "AM").FormulaR1C1 = "=IF(RC[-12]=""No"","""",IF(RC[-3]="""","""",IF(RC[-3]=""On-Going"",""On-Going"",IF(RC[-3]<=60,""OnTime"",IF(RC[-3]<100,""60-100"",""Not on Time"")))))"
Cells(lrow, "AN").FormulaR1C1 = "=MONTH(RC[-30])"
Cells(lrow, "AO").FormulaR1C1 = "=YEAR(RC[-31])"
Range(Cells(lrow, "AJ"), Cells(lrow, "AO")).Select
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
End Sub