+ Reply to Thread
Results 1 to 16 of 16

UDF to remove text from cell formula

  1. #1
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    UDF to remove text from cell formula

    I would like a UDF that removed text from cell contents and gave the result for the remaining numbers, etc. For example:
    Cell A2 contains: 0.25*Pi*[Dia =](1.5^2)*[h]2
    I would like the UDF to remove all instances of [......]
    And in Cell B2 enter UDF(A2) and get the result 3.53 (ie, the volume).
    This would allow me to keep a record in the cell of what the figures represent.
    Help appreciated.
    DesM

  2. #2
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    Sorry, better if Cell A2 contains: [Vol=]=0.25*Pi*[Dia =](1.5^2)*[h]2
    DesM

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: UDF to remove text from cell formula

    If you used named ranges, you could enter the formula as

    =PI() * Dia^2 / 4 * Hgt

    ... which would be pretty clear.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    Yes shg and thanks, I realise this but the time to do this is too much (lots of variable values).
    I end up doing the quick calc on a piece of paper and filing it. I'm trying to do away with this.
    I also know of the way that text can be added to the end of a formula using the "+N(.....)"method but I want to put the text in beside the values in the formula.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: UDF to remove text from cell formula

    try this


    Please Login or Register  to view this content.
    Last edited by kev_; 09-05-2017 at 09:36 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  6. #6
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    kev_, this is fantastic!
    I had figured out the Do and Loop position problem and had it working before I read your mail above. And yes, your first code line now allows it to work with any A2 content.
    I'll be using this twenty times a day! Gone are the scribble notes and the endless naming of cells, and the rows of eg, Dia = xxx, etc.
    Help much appreciated.
    DesM

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: UDF to remove text from cell formula

    You are welcome. Thanks for the rep
    I am sure there is a more elegant method to get there using RegEx - but I have yet to master that!
    Perhaps someone else will come along and post RegEx alternative

  8. #8
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    I'm getting greedy now but would it be a big job to get this to work:
    Cell A2 contains: 0.25*Pi*[Dia =1.5]^2*[h=2] on the condition that the number would always be the only digit between the "=" and the "]"

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UDF to remove text from cell formula

    One way might be
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: UDF to remove text from cell formula

    Try this:

    Array created listing everything to be removed
    - VBA removes everything listed in array
    - so you could add other dimensions (eg "r" for radius etc)
    - just be careful not to remove letters "P" or "I" (or Pi will complain!)
    - adding the "=" moved to the end for obvious reason!

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: UDF to remove text from cell formula

    @xlnitwit - RegEx alternative works perfectly against text in original request
    How is that amended to match request in post#8?

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UDF to remove text from cell formula

    This should work
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    xlnitwit thanks but misunderstanding: the formula that I gave (volume of cylinder) is just an example - it could be any formula and generally much longer than that one.

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UDF to remove text from cell formula

    Are you saying you have one that does not work with that function? If so, what is it?

  15. #15
    Registered User
    Join Date
    06-08-2005
    Location
    Kildare, Ireland
    MS-Off Ver
    Windows/Office 365
    Posts
    41

    Re: UDF to remove text from cell formula

    My apologies, it works perfectly. Thanks very much.
    In fact if I put =removetext("0.25*Pi*[Dia =1.5]^2*[h=4]") into a cell, I get the result without having to use 2 cells.
    Any way of dispensing with the front and end quotes?
    Thanks kindly.

  16. #16
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: UDF to remove text from cell formula

    No, I'm afraid not. If you don't use the quotes, Excel will try and interpret the argument and get very confused.

+ 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. Looking for a simple formula to remove unnecessary text from a cell
    By MichaelMcDanielITI in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-22-2016, 05:38 PM
  2. [SOLVED] Revise formula to remove sapces from text in another cell
    By topaz99 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-01-2015, 01:30 PM
  3. to remove duplicate text within a cell using formula.
    By tell_arshad in forum Excel General
    Replies: 4
    Last Post: 03-10-2015, 04:38 AM
  4. Replies: 6
    Last Post: 03-03-2014, 02:28 PM
  5. [SOLVED] Formula to remove smaller text string in cell
    By LightingPop in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-13-2013, 12:13 AM
  6. Formula to remove text from a cell
    By Backroomgeeza in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-18-2013, 02:40 PM
  7. Replies: 13
    Last Post: 11-05-2011, 03:00 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