Hi, I want to use select case with a named range. the code I'm using is:
Code
Sub Worksheet_SelectionChange(ByVal Target As range)
Dim i As Integer
Dim m As Integer
Dim n As Integer
Select Case Target.Address
'Case "$A$1"
'MsgBox "stop"
'Exit Sub
'not used by now
Case Is = range("named_range1")
MsgBox "it works"
m = Selection.Row
n = Selection.Column
For n = n + 1 To n + 4
With Cells(m, n)
.Interior.Color = RGB(255, 255, 0)
.Value = True
.Font.Color = RGB(255, 255, 0)
End With
With Cells(m + 1, n)
.Interior.Color = RGB(255, 255, 0)
.Value = True
.Font.Color = RGB(255, 255, 0)
End With
Next n
Case Is = range("named_range2")
msgbox "it works2"
m = Selection.Row
n = Selection.Column
For n = n + 1 To n + 4
With Cells(m, n)
.Interior.Color = RGB(146, 208, 80)
.Value = False
.Font.Color = RGB(146, 208, 80)
End With
With Cells(m - 1, n)
.Interior.Color = RGB(146, 208, 80)
.Value = False
.Font.Color = RGB(146, 208, 80)
End With
Next n
'Case "$H$2"
'Set ws = Worksheets("Sheet1")
'Call VBAProject.Module1.test(ws)
'not used by now, but if the code works I will use it
End Select
End Sub
Display More
Now nothing happened, I prefer to not use the if form as usual. The ranges are composed of cells every three rows and every 7 columns, like A1 A8 A4 A8...
thanks for you help!