Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-01
13
Medium Priority
?
326 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
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
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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

916 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