Multiple substitue or replace text in excel using a table - vba

I'd like to create a super substitute function in excel (if there is such a thing). For my needs, nesting is insufficient because my substitution list is long.
What I'd like to do is have a named table with two columns for the function to use as a look-up for potential substitutions. The first column would contain the original text and the second would contain the replacement text.
If we look at the above example, the columns R and S consists of my table, with column R as the original text that I wanted replaced with the equivalent row entry in column S, if found in my list. My data in column V is the list that I want to work on. I want the formula in column W to look at the equivalent entry in column V and lookup in the table for any matches within the text. If there is a match, then I want that text from column R replaced with the text in column S. In some cases there can be 2 matches, as with the top example of 'LHR:JFK' which should ideally get replaced to 'LON:NYC'.
There are ways to do this with VBA but I would like to know if there is an Excel formula option for the same as I don't know where to begin with VBA.
Your help is greatly appreciated.
Thanks,
Neha

This will do as you ask:
=SUBSTITUTE(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3),IFERROR(VLOOKUP(RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3),R:S,2,FALSE),RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3)))

Related

Match, pull and add numbers from different cells on a different sheet

I have data on 'JobSheet1' in Column D, I have Invoice Numbers in ascending order (some are repeated for different products on same order), in Column E, I have amounts i.e £50.00.
On a second sheet 'InvoicesSheet1' in Column B, I have the invoice numbers and Column C is where I would like the total for each invoice number to appear.
Can anyone help with very simple VBA or a formula that will search for the Invoice Number its sitting by in 'JobSheet1' Column D and add all the matching invoice number totals from Column E.
Scott Craner is right, with the schema you described, you will get the result you want entering into cells Ci:Cj (where "i" and "j" are
the start and end of your table, respectively):
=SUMIFS('JobSheet1'!E:E,'JobSheet1'D:D,B{i...j})
If this doesn't work, likely issues you need to watch out for would be:
Sheets are not named exactly as you typed here. Maybe they have a leading or trailing space.
Your copy of Excel/Windows may be set with a different regional setting, which requires that formula parameters be separated by semicolons (;) instead of comas.
Your invoice numbers may not be typed precisely the same in the two different formulas.
Your amounts in column E may not be stored as numeric values. You can test for this by selecting a few values from column E - if excel doesn't show their sum and average in the bottom right corner, they are stored as text and you can't perform math operations on them.
I'd need to see your data to see what could be the issue, but that's not what this forum is for - Try constructing a new table with dummy data set up exactly as you described it here and try using this formula, to verify if it works. Then, adjust accordingly as needed.
Assuming you're first invoice number in InvoiceSheet1 is in cell b3, you can use:
=SUMIF(JobSheet1!D:D,InvoiceSheet1!B3,JobSheet1!E:E).
If it's in another row, replace InvoiceSheet!B3, with the relevant cell where your data starts. Copy down the formula for the other invoices
SUMIFS is not necessary with just one lookup condition.
I solved this by amending the SUMIFS suggestion from ScottCraner and this is what I ended up with
=SUMIFS(Jobs!K:K,Jobs!A:A,D3)+SUMIFS(Jobs!L:L,Jobs!A:A,D3)
Does the job!

Finding string and returning information from an adjacent cell

Using Excel 2010. I need to see if a string in one set of cells exists in another set of cells, and if so, return information from the adjacent cell that matched that string. I had originally done this with SEARCH, ISNUMBER and nested IF statements, but my source data set has several dozen entries in it, and the strings that must be searched has several hundred entries. The data resembles that in the picture (a simplified example):
For a limited data set, I used nested IF statements, like:
IF(ISNUMBER(SEARCH($D$2,$A2,1)),"Cat Info",IF(ISNUMBER(SEARCH($D$3,$A2,1)),"Dog Info",IF(ISNUMBER(SEARCH($D$4,$A2,1)),"Elephant Info","Not Found")))
But now both sets of data are too large to do that on.
What I need to do is to search the strings in column A for the keyword in column D. If the keyword is found, I need to return the corresponding information from column E.
For example, in column B2, since the word dog is in A2, I would want the contents of E3 (Dog Section) to be displayed in B2.
My list of keywords are unique (Column D, List) and I know that zero or one keyword will appear in the string in Column A (TheString).
I think that INDEX & MATCH functions may be part of my solution, but I am unsure how to find which List keyword is in the string and then return the Information column value.
No need for VBA. This can be done with a simple formula:
Enter this formula in cell B2:
=LOOKUP(2,1/SEARCH(D$2:D$7,A2),E$2:E$7)
Copy downward as far as needed.
Note: adjust the range references to the size of your data.
Not done it all, but this formula
=MAX(IF(ISNUMBER(SEARCH(D1,$A$1:$A$4,1)),ROW($A$1:$A$4),0))
Array Formula
Will give you the row of the A1:a4 where D1 etc, is contained. Then you can index on that. However it will only show the max row, so if its in 1 & 2, then it will only show row 2.
Cheers.

Need a simple search function to display most common value in a column. (with ambiguous choices)

I have a very large array of data with many columns that display different outputs for the values presented. I would like to add a row above the data that will display the most common occurring value or word below.
Generally I would like to have each top of the column (right under the column label in row 1) have the most common value below. I will then use this value for various data analysis functions!
Is this possible, and if so, how? Preferably this will not require VBA, but simply a short code in the cell.
One caveat: The exact values may vary, so there is no set list where I can say "it will be one of these."
Any ideas appreciated!
Try a series of =COUNTIF(A:A,"VALUE TO SEARCH") functions if you want to stay away from VBA.
Otherwise, the best method would be to iterate through each column via VBA. With this method, you can even count the "varying" values and return the count and/or the value itself.
http://www.excel-easy.com/examples/most-frequently-occurring-word.html
This is a single formula you would write at the top of each column. Does not require VBA. You can replace the set range to an entire column, such as (A:A) instead of (A1:A7).
If you mean an array as in a data type, it could work differently but it depends what you're trying to do.
With data from A3 through A16, in A2 enter:
=INDEX($A$3:$A$16,MODE(MATCH($A$3:$A$16,$A$3:$A$16,0)))
This will work for text as well as numbers. Adjust this to match the column size.

Create list from data range

I was hoping to get a bit of help regarding formulas in Excel/VBA, I'm looking to do the following but I'm not sure how best to do it:
Okay, so I have a materials export from a piece of software and it comes out with the following sort of data:
In essence I would like to have a catalogue stored on a separate sheet which the function references for text strings that may be contained in a takeoff.
i.e. in E2 the function will check the column B for cells containing the text strings in A16:A18 (the consoles) and return any results along with the corresponding quantity to columns E and F. Similarly this will occur for the controller and cables.
I'm sure there's a solution somewhere but I've been unable to find one for lack of knowing what to search exactly.
Thanks for any help guys, it's appreciated.
What you may want to use is the COUNTIF function. Try this:
COUNTIF(A$2:A$13,"*" & A16 & "*")
If I am not mistaken you can check for the values in A16:A23 in the database dump column B1:B13, then you want the summer quantity for the matching values, where a match means the text you look for must be contained in the database dump column.
To get the quantity accordingly use the following formula in cell B16:
=SUMIFS(C$2:C$13;B$2:B$13;"*"&A16&"*")
then drag it into the other cells. The asterisks are text wildcards, so there may be text in front or behind the text part we look for.

Use Excel/OpenOffice cell names within drag-completition

I have a lot of measured values in each column. I use formulas under those values to calculate with them. I always edit the first column and drag-complete (small square in the south-east of the selected cell) to change the other columns, too.
It was fine while dealing with 5 values, but with 20 values in a formula, things are getting complicated. I would like to use cell names, as I found in Variable in Excel, but when I use drag-complete, this cells are not adapted for the next column, like $D$1 does instead of D1.
Ideas for solutions:
Perhaps I can declare an row of cells as an array and index it with cellname(row), but how is this possible?
Perhaps it is easier with a small vba script, but I would like to avoid this.
Thanks in advance.
Edit 1:
I was afraid that my question is not that clear. I will try to clearify it with the following files. Thus the Excel-Tag is removed, I uploaded an ods-File:
My file looks like the uploaded short example example.ods.
I created cell names in the second column like "size". Then I have put a human readable formula like "=size+step+thickness*weight" in C7. When I drag-complete it to cells D7 and E7 like shown in example.png. I get of course the same result as in C7, because the cell names are used as absolute names like $B$2 for example.
How can I have human readable formulas applied to D7 and E7 without editing D7 and E7 by hand? When I use for C7 "=C2+C3+C4*C5", I can use the drag-completition of course.
I hope this is more clear now. I guess this is some basic functionality, but I just don't know how to describe it well. Perhaps you have a similar idea to have it more readable than "=C2+C3+C4*C5".
This works in OpenOffice.org Calc as well as in LibreOffice Calc, but it's crucial to define the cell names for every column that will be evaluated by the formula. Here's a step-for-step solution, based on the example document:
Start with a spreadsheet containing just the values together with row and column heads:
Create the cell range names:
a. Select the data range including the column holding the row names (OOo will use those Strings as names in the next steps):
b. Select "Insert -> Names... -> Create":
c. Select "Left Column" to name the rows based on the content of the first column:
Result: four names, one for each row, named as desired:
Create the formula for the first data row (here incomplete, demonstrating OOo's tooltips):
Drag-complete for all other data rows, giving the final result (with Tools -> Detective -> Trace precedents activated - the detective points to the array's first column, but the formula will use the values of the current column):
You can use relative references in Names, it easier to use R1C1 mode for this:
Define a Name Size with a RefersTo of =R2C
Then wherever you use the name Size in a formula it will refer to the current column and row 2