Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
Many thanks in advance
Using a function to check a column "E" to the last row if the date format is "DD/MM/YYYY" then it needs to copy the data to the next column "F"
Says DateFormatCheck "Argument not optional" when I try to add function to the command button
Command button code below
Then Function Code below
Using a function to check a column "E" to the last row if the date format is "DD/MM/YYYY" then it needs to copy the data to the next column "F"
Says DateFormatCheck "Argument not optional" when I try to add function to the command button
Command button code below
VBA Code:
Private Sub cmdUpdate_Click()
Dim res As Integer
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("TGS JOB RECORD")
With ws
If DateFormatCheck = True Then .Range("E2:E").Copy Range("F2:F")
End If
End With
ThisWorkbook.RefreshAll
End Sub
Then Function Code below
VBA Code:
Function DateFormatCheck(cells As Range) As Boolean
Dim ws As Worksheet
Dim Rng As Range
Dim LRow As Long
Set ws = thisworkbookworksheets("TGS JOB RECORD")
Set LRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Set Rng = ws.Range("E2:E" & LRow)
DateFormatCheck = False
If IsDate(Rng.Cells.Value) Then
If Rng.Cells.NumberFormat = "dd/mm/yyyy;@" Then
DateFormatCheck = True
ElseIf CInt(Mid(Rng.Cells.Value, 1, 2)) <= 12 Then
DateFormatCheck = True
End If
End If
End Function