+ Reply to Thread
Results 1 to 14 of 14

Getting subscript out of range error - can't figure out why

  1. #1
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Getting subscript out of range error - can't figure out why

    Hi everyone,

    New user, and novice when it comes to vba. What I'm trying to do is change the text color of specific keywords in a spreadsheet. For example, I'd like to highlight the text of 'how to' in the following sentence "I want to know how to change text color", so that it looks like this "I want to know how to change text color".
    I came across the following, and it works for only two terms (example, "how to" , "how do I"), but I have a string of about 15 terms I'd like to use, but anything I change over two, I get the subscript out of range error. Any help would be much appreciated! Thanks!

    Please Login or Register  to view this content.
    Last edited by FumoSanto; 07-23-2014 at 12:29 PM. Reason: tagging code

  2. #2
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    Additionally, I changed the "Cat","Mouse" instances in the example above to meet my "How To", "How do I" needs... Just looking to add more terms in that string. Thanks!

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Getting subscript out of range error - can't figure out why

    Fumo,
    Please use code tags with your code as per forum's no 3 rule.

    This looks Jindon's code.
    In which line does the code errors?
    You can add a comma followed by a string in parenthesis, like
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    It is Jindon's code - that is the one I grabbed. I tried adding more in the string with a comma like your example above, but when I go past two, I get the error.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Getting subscript out of range error - can't figure out why

    I did not get an error on

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    Very strange. I've tried a couple of times, and still get the same issue. The string I'm trying to use is ("how to","how do I","how can","I want to","need to know","is there a way","need to know","question about","questions about","need a","trying to find","need help","what is","where do I find","how can","how-to"), and it works fine using only the first two in the string, but anything beyond that, it errors out.
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Getting subscript out of range error - can't figure out why

    Change myColor(x - 1) to either myColor(0) or vbRed.
    If posting code please use code tags, see here.

  8. #8
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    Thanks Norie, that did the trick!! Now if I can only get it to work on two columns at the same time

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Getting subscript out of range error - can't figure out why

    That shouldn't be to hard, which columns do you want it to work on and what have you tried?

  10. #10
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    For example, I'd want to run the keywords on column A and C (but those may shift if I add more data to the spreadsheet). Additionally (and I'm not sure if this is standard behavior), but the text in red does not translate as such to the preview panel (only the text in the cell changes color). Is that standard behavior? Thanks!
    Last edited by FumoSanto; 07-23-2014 at 07:01 PM. Reason: Additional question

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Getting subscript out of range error - can't figure out why

    If you change the For to this it'll run on columsn A & C.
    Please Login or Register  to view this content.
    Not sure what you mean about the preview panel, when I view the sheet in Print Preview the prhases are highlighted in red.

  12. #12
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    Thanks Norie! That is a huge benefit to get the keyword analysis to where I need it. Thank you so much!! Regarding the preview panel, I meant to say the formula bar - please see the attached image. I like to keep the rows set to a height of 15, but sometimes the cells contain a lot of data, and I expand the height of the formula bar to review, but the keywords don't show as red in that space. Any thoughts as to why color doesn't apply there? Thanks!!Red Keyword.jpg

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Getting subscript out of range error - can't figure out why

    Sorry but formatting won't appear in the formula bar.

  14. #14
    Registered User
    Join Date
    07-23-2014
    Location
    Arizona
    MS-Off Ver
    2007
    Posts
    8

    Re: Getting subscript out of range error - can't figure out why

    Okay thanks, I think this gives me what I need. Again, thanks for all the help!!

+ 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] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  2. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  3. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11:05 AM
  4. Subscript out of range error - save copy error
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 11:53 AM
  5. Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03:06 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