+ Reply to Thread
Results 1 to 8 of 8

Replace variables in string and perform function

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    So Cal
    MS-Off Ver
    Excel 2010
    Posts
    5

    Replace variables in string and perform function

    Hello,

    I building a data mapping/translation function and need help on how to easily to this. I tried searching prior posts but can't seem to find the correct search criteria.

    In a Excel worksheet I have 500 or more cells with info on how to transform the data.

    For example:
    cell A1 contains: "Hello " & a

    in VBA "a" is a variable that can contain "World", for example. So I expect the result to be "Hello world"

    cell A2 contains: "My height is " & a/b & " feet."

    in VBA a = 72 and b = 12 so result will be "My height is 6 feet."

    I've tried Evaluate but doesn't like variables. Is there a easier way to find and substitute variables? I don't mind changing the mapping syntax in the cells to make this easier.

    Thanks for helping.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Replace variables in string and perform function

    why do you want mix formulas with VBA ? attach a sample file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    11-02-2012
    Location
    So Cal
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace variables in string and perform function

    It's for data transformation. I get a pipe delimited file from one application and need to load it to another application but the data does not map one to one so I need to modify it first.

    Source csv file example (shortened otherwise too big). First line is header line:
    ACCT|DATE|Symbol|Qty|MV|Issue Date|Maturity Date|Next Coupon Date
    10330901|20121025|US00206RAJ14|4000000|4903673.6|20080201|20180201|20130201

    Target csv file header (shortened as well):
    Fixed Rate BondSPEC, OBJECT, TYPE, NAME, IDENTIFIER, MarketPriceVAL

    On a Excel worksheet in 2 columns I have:
    Fixed Rate BondSPEC "Fixed Rate BondSPEC"
    OBJECT "Fixed Rate BondSPEC"
    TYPE "Fixed Rate Bond"
    NAME ACCT & " " & Symbol
    IDENTIFIER "Division_" & Symbol
    MarketPriceVAL "$" & MV/Qty

    Is that clear? I am open to other ways to do this but I do like keeping the mapping easily accessible so I can edit, delete or add to without having to go back into code. I've gotten everything else working but the best way to transform the data without parsing each character looking for tags or looping through hundereds for fields to do a find/replace for each field.

  4. #4
    Registered User
    Join Date
    11-02-2012
    Location
    So Cal
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace variables in string and perform function

    Sorry, I tried to separate the 2 columns using spaces but it collapesed them together.

    This is the first column.

    Fixed Rate BondSPEC
    OBJECT
    TYPE
    NAME
    IDENTIFIER
    MarketPriceVAL

  5. #5
    Registered User
    Join Date
    11-02-2012
    Location
    So Cal
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace variables in string and perform function

    The expected output would be (first line header row):

    Fixed Rate BondSPEC, OBJECT, TYPE, NAME, IDENTIFIER, MarketPriceVAL
    Fixed Rate BondSPEC,Fixed Rate BondSPEC,Fixed Rate Bond,10330901 US00206RAJ14,Division_US00206RAJ14,$1.226

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Replace variables in string and perform function

    Why don't you post an excel file without confidentional information.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  7. #7
    Registered User
    Join Date
    11-02-2012
    Location
    So Cal
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace variables in string and perform function

    Too much other codes in the file so not easy to find.

    Basically I tried to use this code but can't get Evaluate to work with variable in it.

    Cells(5,2) contains this: "Division_" & Symbol

    Dim Symbol as String, Identifier as String
    Symbol = "US00206RAJ14"
    Identifier = Evaluate(Cells(5,2))


    I get type mismatch error.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Replace variables in string and perform function

    you could use defined names in place of the variables and then evaluate should work
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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