I always find these sorta things fun.
You can run this macro any time you want, but it relies on something being in the clipboard (copied). Beware that you cannot use Undo....
To use it:
- Copy the cell you want to use as your data source (D2 in your example).
- Click the cell(s) you want the second date inserted into (A2, A3, A5, etc). It'll loop through your entire selection; you can run it for a single cell or a range of cells.
- You can re-run it as many times as you want as long as the data is still in the clipboard.
I added a few error checks since it sounded like data integrity was important to what you're doing. It will show a warning for any of these 3 conditions and not do anything else.
- If the macro is run without anything in the clipboard (i.e. someone ran it without doing a copy first)
- There's no carriage return (chr(10).
- Data was found after the carriage return, but it wasn't a date.
Sub Jayrok_v2()
Dim clippy As Object, cpData As Variant, cpDate As String, err As String
'save data from the clipboard
Set clippy = CreateObject("HtmlFile")
cpData = clippy.parentWindow.clipboardData.GetData("text")
'don't do anything if nothing was copied
If IsNull(cpData) Then
err = MsgBox("No data to paste!", vbCritical)
Else 'data found in clipboard; test data before adding to destination
cpDate = Replace(Mid(cpData, InStr(cpData, Chr(10)) + 1, 10), """", "") 'parse the second date after chr(10)
If cpDate = "" Then
'the copied cell didn't have a second date
err = MsgBox("No date found!", vbCritical)
Else
'is it a real date?
If IsDate(cpDate) Then
'data looks good; add to destination cells
For Each cell In Selection
cell.Value = cell.Value & " " & Chr(10) & cpDate
Next cell
Else
'copied cell has a chr(10), but what follows isn't a date
err = MsgBox("Copied data is not a date!", vbCritical)
End If
End If
End If
End Sub