Greetings Excel Forum,
I am pretty new to using IF statements within VBA, and i'm having a hell of a time trying to get the one i've written to work correctly.
I am trying to get the formula to perform the "Update Current Date" portion of my code to trigger if the first column in the last row is equal to today's date (so as to update the everchanging data of today's data located in "Summary" sheet.)
Sub updatedataset1()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Sheets("dataset1").Select
Set copySheet = Worksheets("Summary")
Set pasteSheet = Worksheets("dataset1")
If pasteSheet.Cells(Rows.Count, 1).End(xlUp).FormulaR1C1 = "=TODAY()" Then
'Update Current Date
copySheet.Range("B2:B9").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(0, 1).PasteSpecial xlPasteValues, transpose:=True
ActiveSheet.Cells(ActiveCell.Row, 1).FormulaR1C1 = "=TODAY()"
ActiveSheet.Cells(ActiveCell.Row, 1).Copy
ActiveSheet.Cells(ActiveCell.Row, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Else
'Add New Date
copySheet.Range("B2:B9").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 1).PasteSpecial xlPasteValues, transpose:=True
ActiveSheet.Cells(ActiveCell.Row, 1).FormulaR1C1 = "=TODAY()"
ActiveSheet.Cells(ActiveCell.Row, 1).Copy
ActiveSheet.Cells(ActiveCell.Row, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
End Sub
However, statement is coming back as false even if the first column of the last row is today's date (perhaps VBA doesnt like comparing formula answers to hardcoded answers?).
Bookmarks