473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA Excel escaping edit mode not working

1
Hi all,

I'm a bit of a VBA newb, but I'm trying to write a small function in a spreadsheet that will execute code on double-clicking a cell and then escape straight out of the cell edit mode. I gather that this is to be done using Cancel = True, which I have tried, but this does not stop the cell going into edit mode. Here is the code so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  2.  
  3. Dim rng1 As Range
  4. Set rng1 = Range("D3:E198")
  5.  
  6.  
  7. If Not Intersect(Target, rng1) Is Nothing Then
  8.  
  9.     If Target.Value = "No" Then
  10.         Target.Value = "Yes"
  11.         Target.Interior.Color = RGB(0, 255, 0)
  12.  
  13.         Cancel = True
  14.  
  15.     ElseIf Target.Value = "Yes" Then
  16.         Target.Value = "No"
  17.         Target.Interior.Color = RGB(255, 0, 0)
  18.  
  19.         Cancel = True
  20.  
  21.     End If
  22.  
  23. End If
  24.  
  25.  
  26.  
  27. End Sub
Any idea why this isn't working?

Thanks,

Simt33
Jun 20 '13 #1
1 1708
Mihail
759 512MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  2.  
  3. Dim rng1 As Range
  4.     Set rng1 = Range("D3:E198")
  5.  
  6.     If Intersect(Target, rng1) Is Nothing Then
  7.         Exit Sub
  8.     End If
  9.  
  10.     If Target.Value = "No" Then
  11.         Target.Value = "Yes"
  12.         Target.Interior.Color = RGB(0, 255, 0)
  13.      ElseIf Target.Value = "Yes" Then
  14.         Target.Value = "No"
  15.         Target.Interior.Color = RGB(255, 0, 0)
  16.      End If
  17.  
  18.      Cancel = True
  19.  
  20. End Sub
Jun 20 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
6
by: Tamir Khason | last post by:
How to prevent the selected cell from being editable (visual) at DataGrid? Once click on cell (even readonly) there are cursor inside it and select text appears. How to prevent it Thankx
1
by: Gilles T. | last post by:
I have calendar control in Javascript including in the Head of mu page: <script charset="iso-8859-1" language="JavaScript" src="popcalendar.js"></script> I call this calendar popup with a image...
1
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field...
2
by: Luqman | last post by:
How can I put GridView and DetailView control to Edit Mode with one click of button ? I don't want to show built-in Edit Buttons of above controls. Best Regards, Luqman
4
by: wandii | last post by:
Hi, I have a datagrid attached to a dataset. It displays the records fine however, when I edit one of the cells it does not change the edit icon to the pencil icon on the left of the row I just...
1
by: phamer | last post by:
Hello. My switchbaord contains 2 options: add a record and edit a record. So, of course, if I click add a record, the first form opens in add mode; if I click edit, the first form opens in edit...
1
by: Mark Stafford | last post by:
I am attempting to use a DetailsView control to view some data where the fields returned by the database are determined at runtime. I create the TemplateFields on the fly using a class that...
1
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
When I click the "Edit" hyperlink, my DetailsView doesn't enter Edit mode. It will if I set the DefaultMode="Edit". Any thoughts? Thanks. <asp:DetailsView ID="DetailsView1"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.