Last week I created this macro that allows me to create a record of my data. It places the data next to the date and is set to replace the date if we are still on the same date (and if not move on to the current date). This is the code:
Sub Record()
'Get all the dates
'Selecting the data to copy
Range("C23:O23").Select
Selection.Copy
'Find the last used row in Column B
Dim LastRow As Range
With ActiveSheet
Set LastRow = .Cells(.Rows.Count, "B").End(xlUp)
End With
'if still today, replace data, if not record the data on the next line
If LastRow = Format(Date, "dd/mm/yyyy") Then
LastRow.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
LastRow.Offset(1, 0).Value = Format(Date, "dd/mm/yyyy")
LastRow.Offset(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Application.CutCopyMode = False
End Sub
The thing is, that last week it worked perfectly. Today when I turned it on, it seems to put the date in American format (07/02/2018 as opposed of 02/07/2018) even though I set the format in the vba code. Thisa renders the macro useless as it still checks against English date format and so skips a line every time I click the button.
Any help would be very much appreciated.
SelectorActiveSheetwhich should be always (if possible - which in this case is) be avoided. Additionally from first glance, it seems like you're mixingPasteandPasteSpecialinto some sort weird hybridLastRow = Format(Date, "dd/mm/yyyy")should never be true. If LastRowm points to text-that-looks-like-a-date then fix your data.If LastRow = Dateshould work which suggests your dates aren't being read as dates. It might be a fairly simple tasks to have VBA read them as dates, or to convert the original data to a true date. How are the dates entered onto the sheet?