+ Reply to Thread
Results 1 to 7 of 7

Auto selecting specific characters in textbox

  1. #1
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Auto selecting specific characters in textbox

    Hi,
    I have a text box in a userform, that contains both a date and a time in a single string, for instance: "02/05/2020 14:00"

    What I want is this:
    say I wanna change the date to 04/07/2020.
    As soon as I type "04", "05" will automatically be highlighted (skipping whatever separator there is, in this case "/") so that i can immediately go on to typing "07" without moving the cursor or fiddle with the arrow keys to position the text cursor manually.

    Or alternatively, allowing the user to jump easily to the next part in the date/time format using the arrow keys.
    Say, if the user clicks the right or left arrow key for example, the next/previous part will be highlighted, ready for the user to change. The user will be able to use the arrow keys to cycle through the different parts ( "02", "05", "2020", "14", "00" )

    I don't have any idea as to how to start.. It's a little out of my vba territory.. that's why I don't even have an initial code to show for.. Sorry..

    Thanks!
    Last edited by guyglk; 05-14-2020 at 06:05 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,023

    Re: Auto selecting specific characters in textbox

    You may want to look into using a date/time picker instead of a textbox for this.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Re: Auto selecting specific characters in textbox

    I don't have it, under additional controls..
    I'll watch some tutorials ..
    Thanks
    Last edited by guyglk; 05-15-2020 at 01:41 AM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,023

    Re: Auto selecting specific characters in textbox

    If you have not solved it yet, please attach your file and I will try to work on it directly.

  5. #5
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Re: Auto selecting specific characters in textbox

    I haven't. I found it too hard for me to set, after watching some tuts (by the way, I also need this functionality in other files (on different computers)). I kinda gave up.. but I'd still want this done if I could impement..
    So I'll attach the file as soon as I can. Thank you so much for the followup 6StringJazzer!

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Auto selecting specific characters in textbox

    Alternative is to enforce numbers only input in the textbox, with exact length.

    Ex: Assuming always mmddyyyyhhmm format (24 hour clock). 12 char length.
    040720201100

    Then use Format() function to format it to date time string, then if needed you can use CDate on it to convert to datetime value.

    Sample code:
    In textbox KeyPress event...
    Please Login or Register  to view this content.
    Then in some other command button (i.e. when you submit form data to sheet etc).
    Please Login or Register  to view this content.
    Now this won't accommodate for users typing in yyyymmddhhmm or some other format. You could validate each key press for valid value only... but that's bit more complicated.
    Ex: Char position 1 must be only 0 or 1, position 2 must be 0-2 if char1 is 1, 0-9 if char1 is 0 etc...
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  7. #7
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Re: Auto selecting specific characters in textbox

    @CK76 thank you! I'll see if it can work for me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Selecting a cells Containing specific Characters
    By pisdukas in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-13-2019, 02:14 PM
  2. [SOLVED] Excel VBA form - textbox to export data over 255 characters from textbox
    By DannyJ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2017, 05:52 AM
  3. [SOLVED] Formatting a Textbox to accept on a specific number of numeric characters
    By DawidV in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-17-2017, 06:18 AM
  4. [SOLVED] Selecting all data in specific columns without selecting adjacent column.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2014, 02:20 AM
  5. Selecting all data in specific columns without selecting adjacent column.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2014, 03:50 PM
  6. [SOLVED] VBA Code for Textbox: First 3 characters Alphabets next 3 characters numeric
    By honger in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2013, 01:05 AM
  7. Auto-selecting of cells to match a specific value
    By yannhk in forum Excel General
    Replies: 1
    Last Post: 09-08-2009, 03:46 PM

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