Doge Robert
New Member
- Joined
- Jan 10, 2017
- Messages
- 14
Hey there.
I have a macro that copies data from one sheet to the first empty row of another... No problem there.
In row H of both datasets is a date. I would like my macro to check if the date in row H of the source sheet (all rows have the same date) is present somewhere in row H of the target sheet, BEFORE data is copied and if the date is present, stop the macro and make a pop up with the text "Data is already copied for specified date".
Any help is appreciated.
This is the macro, I'm currently using:
Edit: Typos
I have a macro that copies data from one sheet to the first empty row of another... No problem there.
In row H of both datasets is a date. I would like my macro to check if the date in row H of the source sheet (all rows have the same date) is present somewhere in row H of the target sheet, BEFORE data is copied and if the date is present, stop the macro and make a pop up with the text "Data is already copied for specified date".
Any help is appreciated.
This is the macro, I'm currently using:
Sub CopyDataToHistory()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim CopyLastRow As Long
Dim DestLastRow As Long
'Set Variables
Set wsCopy = Sheets("TblHistoriskeData") 'Sourcedata sheetname
Set wsDest = Sheets("Historiske Data") 'Target sheetname
'Find Last Row in Copy Range
CopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'Find 1st blank row in Destination Range - Offset 1 row
DestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'Copy & Paste Data
wsCopy.Range("A2:h" & CopyLastRow).Copy _
wsDest.Range("A" & DestLastRow)
End Sub
Edit: Typos