Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-01
13
Medium Priority
?
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
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
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 (Microsoft MVP / EE MVE) earned 2000 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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 the scrolling table in Microsoft Excel using the INDEX function.

715 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