+ Reply to Thread
Results 1 to 12 of 12

Find and Replace Text with SUBSTITUTE formula

  1. #1
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Find and Replace Text with SUBSTITUTE formula

    I have this range of data, which is a takeoff of engineered wood products. The number of Columns are fixed, but the start of the range can occur on different Row numbers. What I would like to do is create a macro that will Find and Replace All the three different values (“-“, “STD.” and “1/16””) in Column A (“MARK”) with a new abbreviated mark, based on the values of Column D (“DIMENSIONS”) and Column E (“GRADE”).

    I would like the new abbreviated mark to follow this nomenclature:

    For all occurrences of “-“ or “STD.”, the new abbreviated mark should read:

    “Abbrev. Dimensions of the beam + Abbrev. Grade”
    Dimensions (only includes the whole number from the width and height of the beam)
    3 1/2” X 11 7/8” = “311”

    Grade:
    2.0E = “LVL”
    1.55E = “LSL”
    30F-E2 = “BB”
    24F-V4 = “GLB”

    Example for Cell “A4” = “311LVL”

    For all occurrences of “1/16””, the new abbreviated mark should read:
    “Abbrev. Dimensions + “HDR”

    Example for Cell “A8” = “511HDR”


    I first approached this by trying to use the SUBSTITUTE function because I knew I’d be able to utilize and manipulate the existing text to create the new abbreviated mark that I wanted.

    So with SUBSTITUTE nested several times, I combined the cell values from Column D and Column E, and removed all spaces, fractions with the inches symbol (in this data set those are quotation marks), and replaced the grade with the abbreviated type. This formula produces the result I want.

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(D13&E13," ",""),"X",""),"""",""),"1.55E","LSL"),"2.0E","LVL"),"24F-V4","GLB"),"30F-E2","BB"),"1/4",""),"1/2",""),"3/4",""),"7/8","")

    The issue with this formula, is that it needs to reference a cell address (in this example, "D13&E13"), which as I mentioned above, the start of the range can occur at different Row numbers because it's entirely dependent on how much material is listed in a given project.

    I was unsuccessful in trying to record this macro, and I don’t know where to start to write this out in VBA. Is it possible to use Substitute and have it reference the address based on the ActiveCell address yielded by Find?

    Using SUBSTITUTE nested seems really convoluted, but as you can imagine there are so many potential combinations of beam types and beam dimensions. This seems like the simplest way to account for all the potential combinations.

    I'd really appreciate any suggestions or input on this. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Find and Replace Text with SUBSTITUTE formula

    So you need to extract integer parts of numbers and add code matching grade to the grade
    The first part is easy
    Please Login or Register  to view this content.
    But code …
    Why two different codes GLB and HDR for the same grade?
    Last edited by BMV; 02-09-2020 at 01:33 AM.

  3. #3
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Find and Replace Text with SUBSTITUTE formula

    "HDR" is abbreviated for "Header". This is also a type of beam but it's specifically located over doors and windows.

    In order for this formula to work, it still needs a cell reference?

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

    Re: Find and Replace Text with SUBSTITUTE formula

    VBA
    Please Login or Register  to view this content.

  5. #5
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Find and Replace Text with SUBSTITUTE formula

    I'm sill confused by HDR and why do you need macro?
    the variants in the file.
    Attached Files Attached Files
    Last edited by BMV; 02-09-2020 at 02:54 AM.

  6. #6
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Find and Replace Text with SUBSTITUTE formula

    Thank you for responding. I tested this macro out, and it seems to work only if the range of data starts at Row 3. Is there a way for this macro to work within any row, and also possibly loop if there is a blank row inserted separating the data?

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

    Re: Find and Replace Text with SUBSTITUTE formula

    Change to
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    Re: Find and Replace Text with SUBSTITUTE formula

    This is how I would do it:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    where Getdim is:
    Please Login or Register  to view this content.

    Edit: Oh, I didn't read the part saying you want a macro, sorry!
    Well, my solution can be easily adapted to a macro.
    Attached Files Attached Files
    Last edited by Jacc; 02-09-2020 at 08:41 AM.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  9. #9
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Find and Replace Text with SUBSTITUTE formula

    This is brilliant, thank you so much!

  10. #10
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Find and Replace Text with SUBSTITUTE formula

    jindon,

    I'm now getting another now Run-time error 9: Subscript out of range. It's highlighting:

    a(i, 1) = Val(Split(x(0))(0)) & Val(Split(x(1))(0)) & myGrade

    I think the error is occurring because there are additional rows above (or below) with "-" in Column A that don't match "myGrade"? Is there a way to modify the code to skip/ignore all other values in Column E , other than what's specified with myGrade?
    Attached Files Attached Files

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

    Re: Find and Replace Text with SUBSTITUTE formula

    You are now asking almost different question.
    You need to upload a workbook showing before/after and the reason.

  12. #12
    Registered User
    Join Date
    02-08-2020
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Find and Replace Text with SUBSTITUTE formula

    So I thought about it, and I realized the easiest way to work around this was to replace all "-" to "--" in Column A IF in Column B = "LP LSL BEAM" OR "LP LVL BEAM". I adjusted your VBA code to search for "--" instead of "-".

    Please Login or Register  to view this content.
    So far this seems to be working. Do you think this makes sense?

+ 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. Replace/substitute after this formula
    By bweil in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-06-2019, 01:15 PM
  2. FIND REPLACE SUBSTITUTE I am not sure which one please help
    By neilclark in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-28-2018, 07:32 PM
  3. [SOLVED] Need help completing a formula to find and substitute a character in a text string...
    By danielneedssomehelp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-27-2014, 11:32 AM
  4. [SOLVED] Need a formula to find and substitute a word in a text if a condition is met...
    By danielneedssomehelp in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-18-2014, 01:34 PM
  5. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM
  6. How to use a substitute formula to substitute text entries to a different text entry
    By andybocchi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-01-2010, 07:50 PM
  7. Substitute, Find or Replace? Need Advice
    By meyero90 in forum Excel General
    Replies: 1
    Last Post: 06-18-2010, 09:24 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