How to associate validation code to a cell versus a button

jnicholas

New Member
Joined
Mar 27, 2003
Messages
14
I am needing to validate the format of a cell immediately after the cell is filled in. I have all the necessary validation code in a macro. When the macro is associated to a form button it performs correctly. What I am doing is checking a cell to make sure it is numeric and not greater than 6 digits, if it is OK I then change the format to A000000. So if 2211 is entered it is changed to A002211, if 22 is entered it is changed to A000022.

I want to associate this macro to the cell so that when the user fills in the cell and moves off, the code is executed. Is this possible or do I have to use a button.
 
Re: How to associate validation code to a cell versus a butt

Thanks for straightening me out. One more question. Is there a worksheet property similar to the SetFocus property of a textbox. I would like to place focus back on the cell that was validated, so the user can correct the input. Have been digging through the help, but have not found anything.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Re: How to associate validation code to a cell versus a butt

No problems.

There are two "on action" things that are very similar: Change and SelectionChange. The two biggest differences are the trigger and the target (cell that the function returns). The Change is triggered when a cell value is changed and the target is the cell that you changed. The SelectionChange is triggered whenever you moves to a new cell and the target is the new cell you move to. Make sense?

Now I'll let you use your new knowledge to figure out how to set the focus back on the invalid input cell. :wink:

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,336
Members
451,697
Latest member
pedroDH

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