You can't do that in a cell; when Excel is in Edit mode, no VBA is running. You could use an ActiveX texbox control and test the length in its Change event.