+ Reply to Thread
Results 1 to 11 of 11

User Input text Colour?

  1. #1
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    User Input text Colour?

    Hi,

    I have a simple macro that allows the user to submit text into a cell with out modifying the existing text:
    Please Login or Register  to view this content.
    How can I get the 'userinput' text to appear in a different colour to the existng text? I'm trying to track the changes to the cell.

    Many thanks

    Steve
    Last edited by Leith Ross; 05-27-2010 at 12:18 PM.

  2. #2
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: User Input text Colour?

    This code adds the inputted text to cell A1 and turns it to the colour in the palette that has index 3 (this is red in the default colours).
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User Input text Colour?

    Runtime error '6'
    Overflow

    ??

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: User Input text Colour?

    Hi, Try this mod to your code:-
    Please Login or Register  to view this content.
    Regards Mick

  5. #5
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User Input text Colour?

    Quote Originally Posted by MickG View Post
    Hi, Try this mod to your code:-
    Please Login or Register  to view this content.
    Regards Mick
    That almost works but it doesnt leave a space between the last word (I added the space to the code) and also highlights the last letter of the the last word

    EG:

    EXISTING TEXT comes out like this

  6. #6
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: User Input text Colour?

    I think the problem with my code was just that I used a Byte instead of an Integer for L, so try this instead:
    Please Login or Register  to view this content.
    The problems you're getting using Mick's modified version are:

    1) L needs to be one greater than the length of the original string, so that when you colour it starts at the next character after the end of your original string.

    2) Because L is greater than the length of your original string, you need to have the If statement in place to stop errors coming up - for example if the use cancels the input box or doesn't enter any text. (Although adding the extra space will help in this case, it's good practice to catch these sorts of things.)

    3) If you want to colour everything from L to the end of your string, you don't need to specify the Length for Character. Specifying Length is the reason your last letter is not getting coloured; without it the colour should go all the way to the end, however many extra spaces you add in..

    4) It's better to use ampersands (&) when concatenating text, rather than plus signs.
    Last edited by Kafrin; 05-27-2010 at 06:56 AM.

  7. #7
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User Input text Colour?

    Please Login or Register  to view this content.
    Thanks for the reply I opted for this method.

    My next mission is transfer this macro to all the other cells I have to update. The format is the same a button to update 'K2' but I need to this across multiple tabs and rows.

    With out creating 100's of macros all doing the same thing with the only difference being the tab.

    Any ideas or is that clear as mud?

    updated the + with &'s thanks
    Last edited by ets2k9; 05-27-2010 at 07:02 AM.

  8. #8
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: User Input text Colour?

    Well, you need to identify the cell you're updating each time, so you can't just point every button directly at the macro.

    Waht you need is to modify the code to this:
    Please Login or Register  to view this content.
    Then create a macro for each button which contains this code, changing the cell each time:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User Input text Colour?

    I'll give it a go thank you

  10. #10
    Registered User
    Join Date
    05-26-2010
    Location
    midlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: User Input text Colour?

    Thats works well - thank you once again.

    Could someone tell me how I would factor an IF statement into the code to account for teh user pressing 'cancel' as a date stamp is still registered?

  11. #11
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: User Input text Colour?

    Cancelling returns an emtpy string, just like pressing OK without actually entering anything, so you need this:
    Please Login or Register  to view this content.

+ 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