+ Reply to Thread
Results 1 to 8 of 8

find how many times a word appears in a string at certain positions within the string

  1. #1
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Question find how many times a word appears in a string at certain positions within the string

    Hi everyone,

    I have strings that are concatenated with ~ characters. an example of the format of the sorts of strings im working with is here:

    (total rows,workbook name,worksheet name,column, top row, bottom row, row 1 data, row 2 data, ... , row total rows-1 data)
    myString = "14~ThisWorkbook.Name~Sheets(1).Name~E~11~25~data0~data1~data2~data3~data4~data5~data6~data7~data8~data9~data10~data11~data12~data13"

    I have kindly been provided with the following code by AlphaFrog which allows me to search this string for a given term and it will count the number of ~ characters to the left of the term.

    code provided by AlphaFrog
    Please Login or Register  to view this content.
    How could I look at this string and count the number of times my term appears only it at certain positions (that is with a certain number of ~ characters to its left).
    The possible positions the term can appear should be restricted to index number 6,13,20,27,..
    by index number i mean the number of ~ characters in front of the term in myString

    so from the above example
    myString index(0) = 14
    myString.index(1) = ThisWorkbook.Name
    myString.index(2) = Sheets(1).Name
    Etc

    The index values to search for should be restricted to those mentioned above.. .. 6,13,20,27,..

    Kind Regards
    Jordan
    Last edited by jordan2322; 02-04-2013 at 09:08 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: find how many times a word appears in a string at certain positions within the string

    Hello Jordan,

    It would help to have more examples to work with and to see what the results should look like. Can you post a copy of the workbook?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: find how many times a word appears in a string at certain positions within the string

    Thanks for your reply Leith,

    I've attached a sample file for you.

    Please note the string examples i've provided in the WB are only to demonstrate how the strings are put together from the data

    Regards
    Jordan
    Attached Files Attached Files
    Last edited by jordan2322; 02-04-2013 at 09:03 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: find how many times a word appears in a string at certain positions within the string

    Hello Jordan2322,

    Thanks for posting the workbook. I would have been completely lost without the examples and explanations.

    Do the numbers 6,13,20,27, etc. indicate the position of the tilde (~) character in the string?

  5. #5
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: find how many times a word appears in a string at certain positions within the string

    they indicate the position of the word in the string. the ~ characters a merely an identifyer.

    the position starts at 0. The positions 0 to 5 are always filled with data which is to be ignored. so relating this back to the example i posted above..

    myString = "14~ThisWorkbook.Name~Sheets(1).Name~E~11~25~data0~data1~data2~data3~data4~data5~data6~data7~data8~data9~data10~data11~data12~data13"

    0 = 14, 1 = ThisWorkbook.Name, 2 = Sheets(1).Name, 3 = E, 4 = 11, 5 = 25.
    From 6 onwards it is all 'cell block' data - the coloured square ranges on the workbook that always consist of 1 column and 7 rows.
    I only wish to search on the first row of these 'cell blocks' for the term. therefore only positions 6, 6+7, 6+7+7, 6+7+7+7, ... etc should be checked to see if they contain the key word.

    I hope this explanation helped and didnt hinder! haha

    Thanks again
    jordan

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: find how many times a word appears in a string at certain positions within the string

    Hello Jordan,

    So everything before the 6th instance of the tilde is to be ignored. Where is the keyword to search for located? Is it in columns L and K?

  7. #7
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: find how many times a word appears in a string at certain positions within the string

    Yes everything before the 6th is to be ignored, then only the words immediately left of the 7th, 14th, 21st tildes should be checked if theyre value is like the term. then return the number of instances this term appears in checked

    For what its worth here is a snippet of the code I am using to compare the values of the string. The strings are stored in an array.
    The code looks for the term in the string, and if it finds the term within the string, it changes the colour of the cells that the string relates to.
    The string contains the workbook, sheet, column, & row information within it, using this information and the split function I am able to make the colour changes to the cells that belong to the String.

    Please Login or Register  to view this content.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: find how many times a word appears in a string at certain positions within the string

    Hello Jordan,


    If you have a blank row separating your cell blocks it would simplify the code. Rows 3 to 10 is a count of 8 rows (inclusive) and 11 to 25 is a count of 15 (inclusive). Are you using 7 rows or 8? If 8 is not being used keeping it blank will make defining a cell block much easier by using the CurrentRegion property. Here is the code I have so far to find the terms and assign the cell block color. This macro is not complete.
    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