+ Reply to Thread
Results 1 to 9 of 9

convert formula to VBA Function

  1. #1
    Registered User
    Join Date
    11-28-2007
    Posts
    45

    convert formula to VBA Function

    Hi all, I am new to VBA functions. I have a requirement to extract substring from a delimited file, and could do correctly using excel formula, though it ended up in long complicated ones! Now I am looking to consolidate all into one button. I tried VBA but some functions when converted to VBA are not working.(Eg . SUBSTITUTE). Is there a way I can use the exact Excel Formula in a VB / or any other way? Should I use Command Button ? Regards,

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,223

    Re: convert formula to VBA Function

    Please give the specification for how you need to extract the substring from the delimited file. It would also be a great help to attach a sample file. If you have a formula that works, please show the formula.

    Do you want a button to act on a single string? Or on strings in multiple rows?

    I'm sure you understand exactly what you need to do but your description is sketchy.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-28-2007
    Posts
    45

    Re: convert formula to VBA Function

    Hi, Thanks a lot for the reply. I have attached my requirements in a word document with excel sheet embedded.
    Regards,
    Attached Files Attached Files

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,223

    Re: convert formula to VBA Function

    It is unclear what your algorithm is for picking out the red parts. It's not consistent. This is what's in your Word file:

    4. In PATH(column E), I need only specific info. This is too lengthy and messy. This delimited file is always have the same structure. I need only the red fond parts to populate as rest of the columns, say from column C , D, E, F and G.

    SOC: Respiratory, thoracic and mediastinal disorders: 10038738; HLGT: Respiratory disorders NEC: 10038716; HLT: Upper respiratory tract signs and symptoms: 10046313; PT: Throat irritation: 10043521; LLT: Throat irritation: 10043521

    For all fields except one, you want to take the text following the label (SOC, HLT, etc.) up until the ":" that precedes the diagnosis code. But after HLGT you also highlighted the next label NEC, which has a colon after it but no description, just a code. It would help if you break this out to show how it is supposed to be broken by column.

    I don't know if you want this

    Respiratory disorders NEC: 10038716

    or this

    Respiratory disorders NEC: 10038716

    Or this

    Respiratory disorders 10038716

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: convert formula to VBA Function

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,223

    Re: convert formula to VBA Function

    Here is a formula solution, which has advantages over a macro solution for this problem. It's always up to date without pushing a button, and you don't have to know VBA if you need to make changes. This is a static solution that really doesn't require VBA.

    I can revised once we straighten out the issue above.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-28-2007
    Posts
    45

    Re: convert formula to VBA Function

    Hi, thanks a lot again! It works the way I want. however I made some silly error! The digits are not required. Only the 'text' part is required. ( like " Respiratory disorders NEC "). To make it more clear I have attached an excel sheet, with expected result, comments in Blue in Result tab. Some additional requirements if possible:

    1. All parts copied over from 'report' tab can be made locked ?
    2. Additional column at the end, Comments. (This should be 'free text' editable field, intended to make entries by users)
    3. Some cosmetic enhancements to look like a more professional report.(Report header, Report time and date. Need 3 rows at the top.) Filter should be ON at row 4, throughout the column headers, Grid line view is not required.)
    4. Column title also added.
    5. Additiaonal column A added.(Details- given in the attached sheet)

    I still prefer VBA, as I need not worry much on maintaining 5 different formula. User may inadvertently delete the blank cell, which in fact has some formula ? Should locking securely will help ?

    Regards, Pras
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: convert formula to VBA Function

    Quote Originally Posted by prasjohn View Post
    Hi, thanks a lot again! It works the way I want. however I made some silly error! The digits are not required. Only the 'text' part is required. ( like " Respiratory disorders NEC "). To make it more clear I have attached an excel sheet, with expected result, comments in Blue in Result tab. Some additional requirements if possible:
    I don't understand this, coz you don't have such data in your latest file.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-28-2007
    Posts
    45

    Re: convert formula to VBA Function

    Hi Thanks again..I did mention all data in my earlier file. However, use the latest file only, for now, as I have made some minor changes to raw data headers. Please find the attached spreadsheet with my comments.See all Yellow highlighted fields.

    Column A ----- Header is correct, (DETAILS) , However data is wrong(from 'scratchy Throat' onwards). This data should be under 'Verbatim' in Column B

    Column A ----- Data should be a concatenated field from REPORT tab. (Excel formula =CONCATENATE(Report!A2,"/",Report!F2,"/",Report!N2,"/",Report!O2) . Fields used here are column A,F,N and O, separated by "/".

    Column B Header is correct, (VERBATIM), however data is wrong,. This data is NOT required. Actual data should come from 'Name' column of Report Tab.(Scratchy throat ..etc.). You have this data under column A now.

    Column C to H ----- Correct, No changes required.

    General ----- GRID lines should be OFF

    General ----- Click button for initialing the program.(in Report tab) as given earlier


    Thanks!, Hopefully this will conclude.
    Regards,PJ
    Attached Files Attached Files

+ 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] Convert Formula to User-Defined Function
    By SoothSailor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2014, 11:53 AM
  2. [SOLVED] How to use a formula or function to convert a plain number into a date format
    By Liam Ryan in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-02-2013, 07:48 AM
  3. Convert Array Formula into VBA User Defined Function
    By hhhhwong in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-05-2013, 12:38 AM
  4. [SOLVED] Convert or add If Function to a formula
    By JohnDear in forum Excel General
    Replies: 5
    Last Post: 12-01-2011, 02:45 PM
  5. Convert formula to excel function
    By thaopham in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-26-2010, 03:06 PM
  6. what function to convert convert 34234 to 99999
    By archiles in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-04-2008, 11:26 PM
  7. complex excel formula Array how do I convert it to a vba Function
    By Rob in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-10-2006, 02:10 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