Solved

i need to detect when the value of the active cell is change

Posted on 2010-09-01
13
320 Views
Last Modified: 2012-05-10
Best regards to all

I need to detect when the active cell on the worksheet is "A2" and after that I need to catch the value of the active cell if it is diferent to empty

0
Comment
Question by:altariamx2003
  • 5
  • 5
  • 2
  • +1
13 Comments
 

Author Comment

by:altariamx2003
ID: 33582166
sorry

the problem is that i need to catch the value (for example in another cell) at the same time that the activecell is editing
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33582204
Hello altariamx,

you can do that with a Worksheet Change event macro.

Right-click the sheet tab and select "View Code". Copy the macro below into the code window and add the steps you want the macro to do.

cheers, teylyn


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [A2]) Is Nothing Then
    If Target = "" Then
        ' do something
    Else
        ' do something else
End If

End Sub

Open in new window

0
 

Author Comment

by:altariamx2003
ID: 33582238
thks teylyn for your example but is not what Im looking for

your code show the value after the active cell change to another one

I need to catch the value of the active cell when you are writing on it



0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 16

Expert Comment

by:Jerry Paladino
ID: 33582335
Can you provide an example with the original cells and values and then - what they should look like after the change?
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33582396
You cannot duplicate a cell content in another cell while you are still editing the cell. You need to confirm the data entry in the cell with one of the known methods (Enter key, tab key, etc) and only then is the cell content available for manipulation via VBA or formulas.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 33582489
While I'm not quite 100% on what you what

This code
- checks to see if A2 was changed
- if A2 is now blank then the value is restored to the prior non blank value (using a static variable)
- if A2 is not blank that the static variable is updated to the new value

Cheers

Dave

Private Sub Worksheet_Change(ByVal Target As Range)
    Static str1 As String
    If Intersect(Target, [a2]) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    If Target.Value = vbNullString Then
        [a2] = str1
    Else
        str1 = [a2]
    End If
    Application.EnableEvents = True
End Sub

Open in new window

0
 

Author Comment

by:altariamx2003
ID: 33582703
mmmm I cannot catch the value????

Ok one last question it is possible to detect when the active cell is editing???

0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33582721
Well, kind of. As far as I know you can't run VBA code while Excel is in edit mode, so not being able to run code might be one indicator.

But maybe you need to step back a bit. Instead of assuming the solution can be achieved with specific technique, why don't you describe what you want to achieve or why you want to do this? That may take us to different approaches.

cheers, teylyn
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 33582729
> why don't you describe what you want to achieve or why you want to do  this?
Seconded

0
 

Author Comment

by:altariamx2003
ID: 33582988
Let me try to explain myself

this is what I try to do

when the cel "a2" is the active cell and is in edit mode I want to detect that state to make visible a combobox (instead the cell )with two values:
  1.- Value 1
  2.- Value 2

When the user select a value from the combobox I would like to assign that value to the active cell .



0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst earned 500 total points
ID: 33583019
Ah! That is called data validation and can be achieved without macros.

Click the cell. Click Data - Data Validation
Select List in the upper dropdown
In the Source box enter the values, separated by commas
Hit OK

Now, when you click your cell, you will see a drop-down arrow and you can select your value from the list.

You can also keep a list of values somewhere else in the sheet and refer to this range in the Data Validation setup. Things get a bit more complicated if you have the list of valid entries on another sheet. In Excel pre 2010 you will need to define a range name and use that as the source.

See the screen shot for referring to a list of values in the same sheet.

cheers, teylyn
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33583031
oops, forgot the screenshots. Here comes:

dataval1.jpg
dataval2.jpg
0
 

Author Comment

by:altariamx2003
ID: 33583344
Sweet!!!

That was a great solution bro

thanks!!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question