Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Selection change code with merged cells

Ian,

Try it this way:

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

HTH,
Bernie
MS Excel MVP


"IanC" wrote in message ...
Hi Ryan

Thanks for the suggestion, but it doesn't work. I've tried it in my original workbook and in a
completely new workbook and the results are the same.

If I put a breakpoint in and step though the code, there are no errors at any point, even though
the tick is not created and Value2(1,1) remains "Empty".

A couple of seconds after I step through "End Sub" I get a message saying that Excel has
encountered a problem and needs to close. It doesn't close properly, though as Excel still appears
in Task Manager Processes (though not Applications)..


"Ryan H" wrote in message
...
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


.





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Selection change code with merged cells

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Ian,

Try it this way:

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

HTH,
Bernie
MS Excel MVP


Thanks Bernie. That works a treat in a blank workbook. I'll try it in my
original workbook tomorrowe, but it's looking promising.

--
Ian
--


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Probklem with code, when merged cells Jan Kronsell Excel Programming 2 November 21st 08 10:24 AM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
Problem with code for merged cells SuitedAces[_25_] Excel Programming 5 July 7th 06 09:40 PM
changing merged cells from code john Excel Programming 7 July 6th 05 10:24 PM
Fine-tuning selection change event for merged cells & wrap text Lucy Barber Excel Programming 0 September 7th 04 10:10 PM


All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"