Validation two ranges in one column

andonny

Board Regular
Joined
Mar 11, 2002
Messages
220
Hi again,
How do I change the macro below if I need to have two ranges in column B
like B1:B12 and B20:B30.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
If Target.Row < 1 Or Target.Row > 12 Then Exit Sub

If Target.Column = 2 Then
If Target.Offset(0, -1) = "" Then
MsgBox "You cannot enter data in Column B if the cell in Column A is blank"
Target.Offset(0, -1).Select
End If
End If

End Sub
Thanks a million
Andonny
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
If Not Application.Intersect(Target, [B1:B12, B20:B30]) Is Nothing Then
If Target.Offset(0, -1) = "" Then
MsgBox "You cannot enter data in Column B if the cell in Column A is blank"
Target.Offset(0, -1).Select
End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,943
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top