简体   繁体   中英

Fill formula until the last row automatically

IF(ISBLANK(B5),"",IF(ISBLANK(O5)=TRUE,"Missing PSD",TODAY()-O5))

This is my formula that calculates the difference between the date in column O and current date. My first filled row with values is 5. The row in which the formula calculation is being done is AC. I want to automatically calculate this until the last filled row and the row values should also increment like it does while dragging down.

I am not good with VBA so any help would be highly appreciated.

Try the next code, please:

Sub testFilFormulaDown()
 Dim sh As Worksheet, lastRow As Long
 
 Set sh = ActiveSheet 'use here the necessary sheet
 lastRow = sh.Range("O" & rows.count).End(xlUp).row 'chosen O:O column, being involved in the formula...
 sh.Range("AC5:AC" & lastRow).Formula = "=IF(ISBLANK(B5),"""",IF(ISBLANK(O5)=TRUE,""Missing PSD"",TODAY()-O5))"
End Sub

In order to properly calculate the last row, you must choose a fully filled column (A:A, C:C etc.). I used one involved in the formula, but since there is a check for blank cells, column O:O could not be the most appropriate one...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM