View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ryan H Ryan H is offline
external usenet poster
 
Posts: 489
Default Selection change code with merged cells

Working with Merged cells sucks sometimes.

1.) When your selection is your merged cells R11:S11 the Target address is
R11:S11. You can't use Target.Value, because this refers to a single cell.
You will have to use Target.Value2(1,1) or Target.Value2(1,2).

2.) Plus you don't have to use the Worksheets("Sheet1") reference when
setting your rTick range variable because it is in the With Sheets("Sheet1")
statement.

3.) Also, why do you have Application.EnableEvents set to False at the
beginning of your code?

4.) I would also declare your rTick variable as a Range.

Try this below. Hope this helps! If so, let me know, click "YES" below.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'----- ENABLE TICKS IN RELEVANT BOXES -----

Dim rTick As Range

With Sheets("Sheet1")
Set rTick = .Range("R11:S12")
If Not Intersect(Target, rTick) Is Nothing Then
With Target
If .Value2(1, 1) = Chr(252) Then
.Value2(1, 1) = ""
Else
.Value2(1, 1) = Chr(252)
.Font.Name = "Wingdings"
End If
End With
End If
End With

End Sub
--
Cheers,
Ryan


"IanC" wrote:

Happy new year everyone.

I have an issue with the code below and wondered if there was a way to get
round the problem.

The issue is that R11:S11 and R12:S12 are merged cells. With single cells,
the code toggles between a tick (Wingdings character 252) and blank when
each cell is selected. With merged cells nothing happens.

Is there a way to enable the code when the cells are merged?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'----- ENABLE TICKS IN RELEVANT BOXES -----
Application.EnableEvents = False
On Error GoTo sub_exit
With Worksheets("Sheet1")
Set rTick = Worksheets("Sheet1").Range("R11:S12")
If Not Intersect(Target, rTick) Is Nothing Then
With Target
If .Value = Chr(252) Then
.Value = ""
Else
.Value = Chr(252)
.Font.Name = "Wingdings"
End If
End With
End If
End With
sub_exit:
Application.EnableEvents = True
End Sub


.