No apologies are needed. Followup questions are allowed and encouraged.
Try:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iRow As Long
Dim bNeedNastyMessage As Boolean
Dim sValueColumnA As String
Dim sValueColumnB As String
Dim sValueColumnE As String
Dim sValueColumnF As String
Dim sValueColumnG As String
Dim sValueColumnH As String
Dim sValueColumnL As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Do Not Allow Data Entry in Columns 'C' thru 'P' if Column 'A' or Column B' is Blank
'Do Not Allow Data Entry in Columns 'Q' if Columns 'E', 'F', 'G', 'H', or 'L' is Blank
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Get the Row Number
iRow = Target.Row
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Column 'A' and Column B' Processing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Process only if the cell selected is in Column 'C' thru Column 'P'
If Not Intersect(Target, Range("C:P")) Is Nothing Then
'Get the values in Column 'A' and Column 'B' (removing leading and trailing SPACES)
sValueColumnA = Trim(Cells(iRow, "A").Value)
sValueColumnB = Trim(Cells(iRow, "B").Value)
'Initialize the 'Nasty Message' Flag
bNeedNastyMessage = False
'Identify if Column 'A' or Column 'B' is Blank
'Put the Focus on the first Blank Column of 'A' or 'B'
If Len(sValueColumnA) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "A").Select
ElseIf Len(sValueColumnB) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "B").Select
End If
'Display a message if Column 'A' or Column 'B' is Blank
If bNeedNastyMessage = True Then
MsgBox "Both Columns 'A' and 'B' must contain data" & vbCrLf & _
"before data can be entered in columns 'C' thru 'P'."
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Column 'Q' Processing
'NOTE: This sections gets processed ONLY if Column 'A' and Column 'B' contain data
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ElseIf Not Intersect(Target, Range("Q:Q")) Is Nothing Then
'Do Not Allow Data Entry in Columns 'Q' if Column 'E', 'F', 'G', 'H', or 'L' is Blank
'Get the values in Column 'A' and Column 'B' (removing leading and trailing SPACES)
sValueColumnE = Trim(Cells(iRow, "E").Value)
sValueColumnF = Trim(Cells(iRow, "F").Value)
sValueColumnG = Trim(Cells(iRow, "G").Value)
sValueColumnH = Trim(Cells(iRow, "H").Value)
sValueColumnL = Trim(Cells(iRow, "L").Value)
'Initialize the 'Nasty Message' Flag
bNeedNastyMessage = False
'Identify if Column 'E', 'F', 'G', 'H', or 'L' is Blank
'Put the Focus on the first Blank Column of 'E', 'F', 'G', 'H', or 'L'
If Len(sValueColumnE) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "E").Select
ElseIf Len(sValueColumnF) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "F").Select
ElseIf Len(sValueColumnG) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "G").Select
ElseIf Len(sValueColumnH) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "H").Select
ElseIf Len(sValueColumnL) = 0 Then
bNeedNastyMessage = True
Cells(iRow, "L").Select
End If
'Display a message if if Column 'E', 'F', 'G', 'H', or 'L' is Blank
If bNeedNastyMessage = True Then
MsgBox "Columns 'E', 'F', 'G', 'H', and 'L' must contain data" & vbCrLf & _
"before data can be entered in column 'Q'."
End If
End If
End Sub
Lewis
Bookmarks