Pinaceous
Well-known Member
- Joined
- Jun 11, 2014
- Messages
- 1,124
- Office Version
- 365
- Platform
- Windows
Good Afternoon,
I have a Private Sub that I have posted onto Sheet1 (Sheet1) that works great on its tab.
Now, if I wanted to have this Private Sub to work on every sheet of the workbook, I thought I would post it onto ThisWorkbook but it does not work upon every sheet of the workbook.
Do I have to change the Private Sub in any way?
This is the code below, in case you need to reference it:
Many thanks in advance!
Pinaceous J
I have a Private Sub that I have posted onto Sheet1 (Sheet1) that works great on its tab.
Now, if I wanted to have this Private Sub to work on every sheet of the workbook, I thought I would post it onto ThisWorkbook but it does not work upon every sheet of the workbook.
Do I have to change the Private Sub in any way?
This is the code below, in case you need to reference it:
Code:
[COLOR=#222222][FONT=Verdana]Private Sub Worksheet_Change(ByVal Target As Range)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim CurrRangeAs String[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim CurrVal AsVariant[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim found AsBoolean[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim x AsVariant, d As Variant[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim c As Range,r As Range[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim cell AsRange[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim dateRng AsDate[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim sDate1 AsDate[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Dim sDate2 AsDate[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] sDate1 =#10/1/2019#[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] sDate2 =#9/30/2020#[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]If Not Intersect(Target, Range("B8:B66")) IsNothing Then[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Set Target =Range("B" & ActiveCell.Row - 1)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] If Target<> Empty Then[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] CurrRow =Target.Row[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] CurrVal =Cells(Target.Row, "B").Value[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] If CurrVal< sDate1 Or CurrVal > sDate2 Then[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Range("B" & CurrRow).Select[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] MsgBox"The Date you Entered: - " & CurrVal & vbCrLf _[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] &"is outside of acceptable date range of 10/1/2019 to 9/30/2020" &vbCrLf & vbCrLf _[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] &"Please correct Date to an acceptable value.", vbOKOnly[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] End If[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] End If[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]End If[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]End Sub[/FONT][/COLOR]
Many thanks in advance!
Pinaceous J
Last edited: