Macro moving data basd on date

Hi

I need I macro that can move data from a registration sheet into a summary sheet, and place the data in the right date row in the summary sheet, considering the date of registration (in cell B8 in the registration sheet). Pleace see attached example. Also I want the macro to see if there is data in the cells in summary sheet before overwriting it (if there was data there already). I.e. if the summary sheet already holds data in the actual date row I want to get a worning before the old data is overwritten.

Please can any of you help.

Thanks Knut

AttachmentSize
registration.xlsx9.84 KB

1. Step 1 Use data validation

1. Step 1
Use data validation (from list) to ensure the date is entered correctly on the registration sheet. This isn't absolutely necessary but is a good idea.

Step 2.
Setup an event triggered macro which is activated by the double clicking on the registration cell. This goes into the sheet1 VBA object. See below.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 2 Or Target.Row <> 8 Then Exit Sub 'Restricts the macro to run only when range B8 changes
TransferData
End Sub

Step 3. The search Macro

Enter the following in the sheet1 VBA module

Sub TransferData()
Dim Y As Integer, X As Integer, TargetRow As Integer, Found As Boolean

Found = False
For Y = 8 To 10000

If Sheet2.Range("A" & Y).Value = "" Then
MsgBox "Selected date not found on the summary sheet"
Exit Sub
End If

If Sheet2.Range("A" & Y).Value = Sheet1.Range("B8").Value Then
TargetRow = Y
For X = 1 To 4
Sheet2.Cells(TargetRow, X + 1).Value = Sheet2.Cells(TargetRow, X + 1).Value + Sheet1.Cells(X + 9, 2).Value
Found = True
Next X

If Found = True Then
MsgBox "Data Transferred to row " & TargetRow
GoTo Skip
End If

End If

Next Y

To use :-
1. Change the date on the registraton sheet
2. Double click on the new date value to activate the transfer macro

Sheet1 Code

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 2 Or Target.Row <> 8 Then Exit Sub 'Restricts the macro to run only when range B8 changes
TransferData
End Sub

Sub TransferData()
Dim Y As Integer, X As Integer, TargetRow As Integer, Found As Boolean

Found = False
For Y = 8 To 10000

If Sheet2.Range("A" & Y).Value = "" Then
MsgBox "Selected date not found on the summary sheet"
Exit Sub
End If

If Sheet2.Range("A" & Y).Value = Sheet1.Range("B8").Value Then
TargetRow = Y
For X = 1 To 4
Sheet2.Cells(TargetRow, X + 1).Value = Sheet2.Cells(TargetRow, X + 1).Value + Sheet1.Cells(X + 9, 2).Value
Found = True
Next X

If Found = True Then
MsgBox "Data Transferred"
GoTo Skip
End If

End If

Next Y

Skip:

End Sub