gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
How can I write this block of code to ensure that if my activeCell in not within 'Rngd'…
- User
How can I write this block of code to ensure that if my activeCell in not within 'Rngd' then the MsgBox "Please select the Reminder Date for the Specific Task you would like to remind the Contractor." appears, F22 is selected and the code stops running. Currently this is not happening with the code below.
Dim wordApp As Object Dim doc As Object Dim WshShell As Object Dim Rng As Range Dim Rngd As Range Dim RowNum As Integer Dim cell As Range RowNum = activeCell.Row Set Rng = Range("D" & RowNum & ":H" & RowNum) Set Rngd = Range("D23:D523") Set cell = activeCell
'If RowNum < 23 And activeCell.Column <> 6 Then If Rngd Is Nothing Then MsgBox "Please select the Reminder Date for the Specific Task you would like to remind the Contractor." Range("F22").Select Exit Sub Else - Assistant
Updated code:
Dim wordApp As Object Dim doc As Object Dim WshShell As Object Dim Rng As Range Dim Rngd As Range Dim RowNum As Integer Dim cell As Range RowNum = ActiveCell.Row Set Rng = Range("D" & RowNum & ":H" & RowNum) Set Rngd = Range("D23:D523") Set cell = ActiveCell If Not Intersect(ActiveCell, Rngd) Is Nothing Then ' Your existing code here Else MsgBox "Please select the Reminder Date for the Specific Task you would like to remind the Contractor." Range("F22").Select Exit Sub End IfExplanation:
- Intersect function is used to check if the activeCell is within the range Rngd. If they intersect (i.e. not Nothing), the existing code will be executed.
- If the activeCell is not within Rngd, the message box will appear, F22 will be selected, and the code will stop running.