Prevost
Board Regular
- Joined
- Jan 23, 2014
- Messages
- 198
Hi There,
I have a question regarding the code below which is written on a worksheet. Firstly, does all code written on a worksheet have to be named "Worksheet_SelectionChange"? And what is "ByVal Target" mean? Lastly, the line "If Not Intersect(Target, CheckRange) Is Nothing Then" is not quite clear to me. Is this a double negative? I would have thought that if the cell intersect was selected I could just write "If Intersect(Target, CheckRange) Then". However, this does not seem to work. What is going on? This would help me understand the code so that I know what to do in the future so if anyone has any insight or clarifications that would be greatly appreciated!
Thanks.
I have a question regarding the code below which is written on a worksheet. Firstly, does all code written on a worksheet have to be named "Worksheet_SelectionChange"? And what is "ByVal Target" mean? Lastly, the line "If Not Intersect(Target, CheckRange) Is Nothing Then" is not quite clear to me. Is this a double negative? I would have thought that if the cell intersect was selected I could just write "If Intersect(Target, CheckRange) Then". However, this does not seem to work. What is going on? This would help me understand the code so that I know what to do in the future so if anyone has any insight or clarifications that would be greatly appreciated!
Thanks.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim CheckRange As Range
Set CheckRange = Range(Cells(6, 9), Cells(500, 9))
If Not Intersect(Target, CheckRange) Is Nothing Then
Message = MsgBox("Would you lke to enter this date into all date cells?", vbYesNo, "Enter Date")
If Message = vbYes Then
i = ActiveCell.Row
Call EnterDateMultipleCells
Cells(i, 11) = Cells(i, 9)
Cells(i, 15) = Cells(i, 9)
Cells(i, 17) = Cells(i, 9)
Cells(i, 21) = Cells(i, 9)
Cells(i, 23) = Cells(i, 9)
Cells(i, 27) = Cells(i, 9)
Cells(i, 29) = Cells(i, 9)
ElseIf Message = vbNo Then
Call EnterDateMultipleCells
End If
End If
End Sub