the vba copies data from the "source" to the "final" tab based on a date entered by the user the source has been reformatted (columns removed and added etc) in an "export" tab prior being copied in to the "final" tab. the vba below works but, I want to tighten the process and avoid the user from simply clicking on ok or cancel as this results in all data from the source spreadsheet being copied
Public Sub Copydata()
Dim CopySheet As Worksheet
Dim PasteSheet As Worksheet
Dim FinalSheet As Worksheet
Dim nextRow As Long
Dim FinalRow As Long
Dim lastRow As Long
Dim thisRow As Long
Dim myValue As Date
Set ws = ThisWorkbook.Sheets.Add(After:= _
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ws.Name = "Export"
' Get the sheet references
Set CopySheet = Sheets("Source")
Set PasteSheet = Sheets("Export")
Set FinalSheet = Sheets("Final")
lastRow = CopySheet.Cells(CopySheet.Rows.Count, "B").End(xlUp).Row
nextRow = PasteSheet.Cells(PasteSheet.Rows.Count, "A").End(xlUp).Row + 1
myValue = InputBox("Enter start date to transfer", "Input Date")
For thisRow = 1 To lastRow
If CopySheet.Cells(thisRow, "B").Value >= myValue Then
CopySheet.Cells(thisRow, "B").EntireRow.Copy Destination:=PasteSheet.Cells(nextRow, "A")
nextRow = nextRow + 1
End If
Next thisRow""
I had thought about a loop until the date was entered something like:
Do
myValue = InputBox("Enter start date to transfer", "Input Date")
If myValue = "" Then
MsgBox "You must enter a date as dd/mm/yyyy", vbOKOnly, "Invalid Date"
Else
Exit Do
End If
Loop
But it just loops even if a date is entered and doesn't carry on with the code or errors with a type mismatch.
Any guidance would be appreciated thank you