Avatar of pdvsa
Flag for United States of America

asked on 

VBA code to return end of previous month (if cell is blank)


How can I change the row  rCell2.Value = Date - Day(Date)  to return the end of the previous month if there is no data in the cell?
Right now, the code works as planned in all cases but returns a blank if the cell is blank.

 Range(Selection, Selection.End(xlDown)).Select
    Dim rCell2 As Range

    For Each rCell2 In Selection
        If IsDate(rCell2) And Not rCell2.HasFormula Then
             rCell2.Value = Date - Day(Date)
        End If
    Next rCell2

Open in new window

thank you very much
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment

8/22/2022 - Mon