+ Reply to Thread
Results 1 to 5 of 5

Excel macro to add html tags to specific phrases in one worksheet

  1. #1
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Excel macro to add html tags to specific phrases in one worksheet

    I have an Excel worksheet with one column that contains over eight thousand of multiple choice questions each is followed by an empty cell to separate it from the following question, as per the following example.

    Type: MC
    1) What is the effect of releasing a ball in positive gravity?
    ~ It will fall down. (This is the correct answer) It will retain its mass. (This answer is true but unrelated) It will rise. (This answer is false but related) Its shape will change. (This answer is false and unrelated) It will explode. (This answer is false and unrelated)
    @ It will fall down. (This is the correct answer) It will retain its mass. (This answer is true but unrelated) It will rise. (This answer is false but related) Its shape will change. (This answer is false and unrelated) It will explode. (This answer is false and unrelated)
    *a. It will fall down
    b. It will retain its mass
    c. It will rise
    d. Its shape will change
    e. It will explode

    What I'm requested to do is to change the colour of all the items in the two paragraphs that start with "Tilde ~" and "Ampersand @" as long as they exist in the list of alternative answers "a. – k.". In other words to parse the list of alternative answers for each question (in my example a. to e.), and only change their corresponding phrases in the above two paragraphs that start with "~" and "@", by adding relevant html tags. Thus each question will become as follows:

    Type: MC
    1) What is the effect of releasing a ball in positive gravity?
    ~ <font color = "#008000">It will fall down</font>. (This is the correct answer) <font color = "#008000">It will retain its mass</font>. (This answer is true but unrelated) <font color = "#008000">It will rise</font>. (This answer is false but related) <font color = "#008000">Its shape will change</font>. (This answer is false and unrelated) <font color = "#008000">It will explode</font>. (This answer is false and unrelated)
    @ <font color = "#008000">It will fall down</font>. (This is the correct answer) <font color = "#008000">It will retain its mass</font>. (This answer is true but unrelated) <font color = "#008000">It will rise</font>. (This answer is false but related) <font color = "#008000">Its shape will change</font>. (This answer is false and unrelated) <font color = "#008000">It will explode</font>. (This answer is false and unrelated)
    *a. It will fall down
    b. It will retain its mass
    c. It will rise
    d. Its shape will change
    e. It will explode

    .. another question

    .. another question

    Can someone help with this request? Many thanks in advance.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Excel macro to add html tags to specific phrases in one worksheet

    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Excel macro to add html tags to specific phrases in one worksheet

    My deep thanking to you pjwhitfield for your prompt reply. Please pardon my ignorance, as I have been trying to run the code, but a message comes up as "Run-time error '9', Subscript out of range". How do you think I should fix this error?
    My best regards.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Excel macro to add html tags to specific phrases in one worksheet

    When does it happen? Ive only tested against half a dozen entries and it worked against those....check how many entries have been amended.

  5. #5
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Excel macro to add html tags to specific phrases in one worksheet

    My apologies, it was actually some entries in the data file itself. Having fixed it, the code ran like a charm. Thank you very much pjwhitfield for your genius code.

+ 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] Using HTML tags in Excel VBA
    By Excel Guy 123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-18-2014, 12:44 PM
  2. extract information from webpage html tags to excel
    By b.hill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-06-2012, 01:24 AM
  3. convert formated excel column to html source text with html tags
    By julia81 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2011, 04:22 PM
  4. Remove html markup tags in an EXCEL cell?
    By glennwhite in forum Excel General
    Replies: 3
    Last Post: 06-05-2006, 02:30 AM
  5. [SOLVED] Replacing HTML Tags in Excel
    By Darlene in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2005, 03:05 PM

Tags for this Thread

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