+ Reply to Thread
Results 1 to 13 of 13

Highlight textbox if date <=60 days referencing an array as textbox numbers

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Highlight textbox if date <=60 days referencing an array as textbox numbers

    A dblclick event loads a userforms textboxes from 1 to 46

    textboxes 27,29,31,33,37,39 and 41 are expiry dates, I am trying to highlight these if due with 60 days

    I have tried various forms of this but just cant seem to be able to reference the array value only
    When I try using "For j =" a message box appears saying Expected "To"

    Please Login or Register  to view this content.
    Any pointers appreciated

    the code to load the userform is
    Please Login or Register  to view this content.
    Last edited by nigelog; 03-23-2017 at 11:40 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    Assuming the code runs in a userform.

    Please Login or Register  to view this content.
    To loop through the controls.

    Please Login or Register  to view this content.
    Using a phone so not sure which is the problem for you, but that's how to loop through controls and 1 way to loop through an array.
    Last edited by cytop; 03-23-2017 at 10:19 AM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    To give you an idea how it works.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    Hi Cytop
    Will not accept
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Its the referencing of the array that seems to be the issue
    Last edited by nigelog; 03-23-2017 at 10:27 AM.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    thanks Bakerman, Ill have a look

    Your code was handy to understand the array principal so got as far as here
    Please Login or Register  to view this content.
    The error now is on the reading of the actual textbox value
    Last edited by nigelog; 03-23-2017 at 10:33 AM.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    Or in full.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    Thanks Bakerman I learnt a valuable usable method of referencing an array

    Code still highlights the
    Please Login or Register  to view this content.
    Im guessing the code loading the form is loading the data as text rather than a date value
    All Textbox dates are displayed in "dd mmm yyyy" if that makes a difference (No I checked and loaded in "dd mm yyyy" format but still same)

    I ran without that line and textboxes are highlighted so it is the DateValue is problem. Ill look it up.
    Last edited by nigelog; 03-23-2017 at 10:57 AM.

  8. #8
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    The problem is how you are referring to the controls... To start with, at least.

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    Also tried this as but no go
    Please Login or Register  to view this content.
    All relevant textbox dates are displayed as "dd mm yyyy" but just not reading the datevalue

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    @ cytop

    Missed that one.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    You also need to test the textbox contents can be coerced to a date - and a blank textbox will raise an error. It also needs a check if the procedure runs again to remove the colouring from any textboxes which may have had invalid dates earlier, but now have valid dates...

    Sorry to try and take this a different direction, but I think the following is easier to follow the logic.
    Please Login or Register  to view this content.
    Last edited by cytop; 03-23-2017 at 11:36 AM.

  12. #12
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    @ cytop

    Perfect, thankyou...can use that in a few other areas

    @ Bakerman

    Many thanks

    I will mark as solved
    Please Login or Register  to view this content.
    Last edited by nigelog; 03-23-2017 at 11:50 AM.

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Highlight textbox if date <=60 days referencing an array as textbox numbers

    You're welcome and thanks for rep+.

+ 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. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  2. [SOLVED] Type in TextBox after referencing a different Textbox
    By WAYNE005 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-05-2014, 06:50 PM
  3. highlight textbox when selected
    By lifeseeker1019 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2014, 07:33 PM
  4. Highlight Row from TextBox in Userform
    By lsteinbach in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2013, 05:07 PM
  5. Highlight text within a textbox
    By jpruffle in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-07-2009, 02:30 PM
  6. [SOLVED] Highlight the contain of textbox and radio button
    By Peter Cheang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-11-2006, 11:55 AM
  7. Highlight all Text in a Textbox when the textbox is selected
    By RPIJG in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2005, 03:28 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