Worksheet change function to add enter to specific column

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
829
Office Version
  1. 365
Platform
  1. Windows
I have a column (D) with a manually keyed in number. I would like to input either a positive or negative number in column E and then automatically add or subtract the E value to the D value and clear the contents of E.

If D contains the value of 100 and I key in 25 in column E, the value in column D would change to 125 and column E would then be blank.

I feel that a worksheet change function would do this, but I have no idea where to begin.

Matthew
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Re: Worksheet change function to add enter to specific colum

Paste in the code module for the WS in question:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
    <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Or</SPAN> Target.Column <> 5 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>
    Target.Offset(, -1) = Target.Offset(, -1) + Target
    Target.ClearContents
    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>



</FONT>
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

I pasted the above code into the worksheet, but I see no changes occuring.

When I key in any number in column E and press return, the number is still present and no change is being made to the number in column D.

What am I missing here???

Matthew
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

You pasted it into the worksheet or into the worksheet code module?
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

I opened the workbook in question, opened the VB editor, double clicked on the sheet where I need to perform this action, and pasted the code into the right window pane.

Is this not correct?

Matthew
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

Nope - that's spot on. Forgive the question, but this should be pretty straightforward, so didn't want to overlook the obvious.

Hmmm, I can think of maybe two other things that might be interfering...
- What's your macro security set to?
- In the Immediate Window in the VBE, if you type ? application.enableevents do you get True?
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

Marco security is set to medium. The sheet that I am working with does have other macros but I enabled them when opening the page.

When I key in application.enableevents and press return, it changes to:

Print Application.EnableEvents

I was just hoping to your suggestion working so that I would not have to load the RECALL() add-in.

Matthew
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

If ? xxx turned into Print xxx then you typed it into a code window not the Immediate window. To see the Immediate window hit Ctrl+G or menu optionsView | Immediate Window. This allows you to test code/environment interactively. Does ? application.enableevents return True ?
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

That is a negative. I get FALSE when I type that in.

BTY - I was not aware of that Window. I always learn something new on this board.

Matthew
 
Upvote 0
Re: Worksheet change function to add enter to specific colum

OK - in the Immediate window type Application.EnableEvents = True. Does it work now?
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top