+ Reply to Thread
Results 1 to 4 of 4

Keeping the cursor in a cell to ensure a valid entry is made

  1. #1
    Registered User
    Join Date
    04-18-2011
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    6

    Keeping the cursor in a cell to ensure a valid entry is made

    Hi folks,

    I am trying to implement some functionality that will keep a cursor in a cell until a valid entry is made.

    I had used the Workbook_SheetChange sub (using VBA) to detect changes in the cell and then called a routine to check for invalid characters. this all works and i can raise the MsgBox to indicate the error then select the cell and go back to it but then it doesnt get triggered again. when i clikc another cell or hit CR I was hoping the checkl would be made again but becuase the cell value hadnt changed from the previous time then the workbook change routine rightly isnt triggered.

    So my problem is I need to know how to keep the cursor in the cell until a valid entry is made.

    any help greatly appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Keeping the cursor in a cell to ensure a valid entry is made

    Hi,

    One way would be to declare a Public variable at Module level, say 'bError As Boolean' and set this to TRUE when the error MsgBox condition is met, and set it to FALSE when valid characters are entered.

    Then at the start of your Workbook Sheet Change event use

    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-18-2011
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Keeping the cursor in a cell to ensure a valid entry is made

    Hi Richard.

    I tried this but no joy. Using the debugger to stop at the Workbook_SheetChange sub for the sheet in question. I have noticed that if i attempt in any way to change the content of the cell or even remove an invalid charracter and then type the invalid character back in the sub proess is triggered.

    My problem is that after an initial attempt to type in a value which is wrong, the cursor correctly puts me back there but if i then hit the CR button or click to another cell, the sub isnt called as nothing has actually changed.

    I am trying to work out where I can put the code to actually put me back in the cell if the value is wrong even though the initial check was performed.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Keeping the cursor in a cell to ensure a valid entry is made

    Hi,

    Would you upload the workbook in question and identify the relevant cells and valid characters etc.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1