+ Reply to Thread
Results 1 to 11 of 11

processing a string by Excel

  1. #1
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string by Excel

    Hi,
    I get equation in the form of a string from the output of a software that I want to modify by Excel. I am no expert in Excel and I am wondering if some expert in Excel at this forum can do this for me.
    Pls see the attached Excel file. The string in cell A1 is an example string that I will be explaining how I want this string to be modified. Here are the attributes of the string.

    a. The string will have ASCII characters in it.

    b. The string is a mathematical equation. I will be pasting it into Mathcad once the Excel program modifies it.

    c. The string has parameters and mathematical operators in it (+,-,*,/,^). Each parameter is seperated from another parameter by at least one space. There is no space in a parameter. So, each parameter starts with a space and ends with a space. The parameters of the example string in cell A1 are listed from cells A5 to A14 in the attached file.

    d. If a parameter has paranthesis in it (), then the program will disregard any character in the parameter outside the paranthesis and take the characters inside the paranthesis. For example, it will modify the parameter in cell A5 from "F(u)_X1" to "u". If the parameter has no paranthesis in it, like the one in cell A14, then it will take it as is.

    e. The format of the string is such that the multiplication sign may be omitted between parameters. If there is no mathematical operator between two adjacent parameters, it should be assumed that the math operator between them is multiplication. So, the Excel program should insert a multiplication sign between them.

    f. Then the program will reassemple the string in the form of an equation by appropriately keeping the mathematical operators in the original expression.

    The cells B5 to B14 show the modified parameters of the original parameters in the string in cell A1. The Excel program should put together the parameters in B5 to B14 as shown in cell A18.

    I will appreciate if someone can write an Excel program for me that accomplishes this. Many thanks.

    Mark Neil
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    I think this will do what you want - It can only cope with one lot of multiple (( & )) brackets

    It only looks at cell A1 & displays the result in a message box

    Code can be modified to run down a column & place the result into another column

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string by Excel

    Hi Mudraker,
    Thanks a lot for your reply. I appreciate it.
    I have noticed an error in the expression. There is a redundant * sign right before the closing paranthesis in the example in Book1.xls file. It should not there. Also, I have run the script on more examples and noticed that it doesn't do quite what it is supposed to do. One more thing is that I will copy the resultant expression and paste it in Mathcad. Can the program write the result in a cell instead of message box?
    I have attached another Excel file (Book11.xls) to this post including more examples for string. Cell A1 is the same example as you worked on. Cells A2 and A3 are new examples to test the script for.
    The strings have parantesis that grabs the whole expression as well as paranthesis in the string parameters. It requires extra effort in programming to diffrentiate between them. Therefore, I have the option to use some other type of parantesis in the parameters. For example, I can use square brackets "[]" or curly parantesis "{}" in the parameters. I think this may make the programming easier since the program keeps the paranthesis as is () and detects the square brackets (or or curly paranthesis) in the parameters and modify the expression accordingly. Cell A4 in the attached file has an expression that uses square brackets within parameters. The expression in A4 is the same expression as in A3 except the square brackets. Cells A7 to A9 has the modified expressions of the strings in A1 to A3, respectively.

    Thanks in advance.

    Mark Neil
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string

    Norm,
    Thanks for your help.
    I have added three more examples of string in the file attached (Book111.xls). The first three are the same as in Book11.xls. But I changed them so that parameters have brackets instead of paranthesis.
    Strings from A4 to A6 are new.
    I have noticed that the parameters in the string A1 have extra characters after a closing bracket "]" while all the parameters in the strings in A2 and A3 end with a bracket. I have a hunch that if you add to the program the intelligence that it ignores rest of the parameter until the next space once it detects a closing bracket, it would work just fine.
    Thanks.

    Mark
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Mark

    It's taken a while to get all the bugs out.

    The answers you supplied for the last 2 equations, to me appears to be incorrect - You left a ] in both of them & the last one is missing the 1st )

    The extra examples helped me to code the macro to deliver the results you are after

    This macro loops through column A starting at row 1 to the last used row in column A, Places the result in column B of the same row

    Please test as fully as possible.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string by Excel

    Hi Norm,
    Thanks a lot for your effort in writing this program. I have tested it in few sample strings and it works just fine. This was great help for me.
    Could you do a minor modification to this program? Instead of writing the result to column B, can you write them to column A in order by skipping one row from the last expression.
    Even if this is not done, the present version does the job for me. Thanks a lot again :-)

    Mark.

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Mark

    Glad to hear the macro works.

    With the required changes is their already a blank cell under each entry in Column A that the macro can just place the formula into or will the macro need to insert a blank row before it places the formula into column A

  8. #8
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string by Excel

    Hi Norm,
    The program already finds how many rows populated in column A and writes the results in column B in each respective row. Say, rows from A1 to A4 contain formulas. I prefer to see the results from A6 to A9 in order having A5 empty.
    Thanks a bunch.

    Mark.

  9. #9
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Mark

    If I understand what you are after correctly this version will work.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-08-2007
    Location
    New York
    MS-Off Ver
    2007 and 2010
    Posts
    13

    processing a string by Excel

    Many thanks. The programs does what I want it to do.

    Mark.

  11. #11
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Glad to hear that it solves your problem

+ 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