Replace cell reference in =formulatext output with variable name - vba

I am working on a excel sheet where I need to show the formula that is used in another cell. I have 2 tables. Table one contains:
+-----------+-------+-------+------+
| Parameter | Short | Value | Unit |
| Name | | | |
+-----------+-------+-------+------+
| Diameter | D | 50 | mm |
+-----------+-------+-------+------+
| Wanddikte | T | 5 | mm |
+-----------+-------+-------+------+
| Lengte | L | 200 | mm |
+-----------+-------+-------+------+
And the second table:
+----------------------+-------+-------------+------+-----------------+
| Name | Short | output | Unit | Formula |
+----------------------+-------+-------------+------+-----------------+
| Doorsnede oppervlakt | A1 | 1963,495408 | mm | =0,25*PI()*C3^2 |
+----------------------+-------+-------------+------+-----------------+
| Binnendiameter | ID | 40 | mm | =C3-2*C4 |
+----------------------+-------+-------------+------+-----------------+
| Verfoppervlakt | Averf | 31415,92654 | mm2 | =PI()*C3*C5 |
+----------------------+-------+-------------+------+-----------------+
Now I want to change the last column of the second table. There you see the cell references: C3, C4 and C5.
Those refer to cells in the first table (Value column). But instead of showing C3 (value= 50 in table1) I want to show D (Short in table 1).
The last column in table 2 contains the excel formula: =FORMULATEXT(...) which refers to the output calculation in table 2.
How do I replace cell references with values from the Short column in the last column of the second table ?

1) You could use named ranges.
For example: C3 would be a named range called D. Then in your formula you would write =25*PI()*D^2 and you would have the FORMULATEXT as requested.
C4 would be a named range called T and C5 a named range called L.
To create the named range click on the cell you want to enter the name for e.g. C3 then go to the Name Box top left and enter then name e.g. D.
See here: Named ranges
2) Consider having a helper column where you put the following:
'=0,25*PI()*D^2 . Hide the column where you have the FORMULATEXT result and leave the helper column visible. The ' at the start means Excel will not try to evaluate the cell contents.
I think this might appear confusing if you use a simple letter such as D. This is not descriptive of what D actually is and can be confused as a partial cell reference.

Related

Excel: How to match a string and find all row data?

I have 2 sheets, A and B.
A includes rows with a given slug, and a few 'metrics' columns.
Slug | Views | Shares
aaa | 10 | 5
bbb | 25 | 2
ccc | 5 | 0
Sheet B has a huge list of slugs (some which might not be contained in sheet A).
I basically want to "search" sheet A by slug value, and "fill in" those corresponding values.
Here's a sample output of sheet B:
Slug | Views | Shares
xxx | - | -
bbb | 25 | 2
aaa | 10 | 5
ddd | - | -
eee | - | -
I will eventually perform some math on them when moving them over, but this is the start I need before I can do that.
Use VLOOKUP.
For example to get the 25 in bbb in sheet B, the formula would be:
=VLOOKUP(A2,A!$A$2:$C$4,2,FALSE)
The first argument A2 is bbb in sheet B, the second argument is the table in sheet A, the third argument says to return column 2 (the Views column), and the final argument indicates exact match.

How to inner-join in Excel (eg. using VLOOKUP)

Is there a way to inner join two different Excel spreadsheets using VLOOKUP?
In SQL, I would do it this way:
SELECT id, name
FROM Sheet1
INNER JOIN Sheet2
ON Sheet1.id = Sheet2.id;
Sheet1:
+----+------+
| ID | Name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
+----+------+
Sheet2:
+----+-----+
| ID | Age |
+----+-----+
| 1 | 20 |
| 2 | 21 |
| 4 | 22 |
+----+-----+
And the result would be:
+----+------+
| ID | Name |
+----+------+
| 1 | A |
| 2 | B |
| 4 | D |
+----+------+
How can I do this in VLOOKUP? Or is there a better way to do this besides VLOOKUP?
Thanks.
You can acheive this result using Microsoft Query.
First, select Data > From other sources > From Microsoft Query
Then select "Excel Files*".
In the "Select Workbook" windows, you have to select the current Workbook.
Next, in the query Wizard windows, select sheet1$ and sheet2$ and click the ">" button.
Click Next and the query visual editor will open.
Click on the SQL button and paste this query :
SELECT `Sheet1$`.ID, `Sheet1$`.Name, `Sheet2$`.Age
FROM`Sheet1$`, `Sheet2$`
WHERE `Sheet1$`.ID = `Sheet2$`.ID
Finally close the editor and put the table where you need it.
The result should look like this :
First lets get a list of values that exist in both tables. If you are using excel 2010 or later then in Sheet 3 A2 put the following formula:
=IFERROR(AGGREGATE(15,6,Sheet2!$A$1:$A$5000/(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000)>0),ROW(1:1)),"")
If you are using 2007 or earlier then use this array formula:
=IFERROR(SMALL(IF(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000),Sheet2!$A$1:$A$5000),ROW(1:1)),"")
Being an array formula, copy and paste into the formula bar then hit Ctrl-Shift-Enter instead of Enter or Tab to leave the edit mode.
Then copy down as many rows as desired. This will create a list of ID'd that are in both lists. This does assume that ID is a number and not text.
Then with that list we use vlookup:
=IF(A2<>"",VLOOKUP(A2,Sheet1!A:B,2,FALSE),"")
This will then return the value from Sheet 1 that matches.
For Basic Excel Join without formuales or Excel Macros. Please check the website
http://exceljoins.blogspot.com/2013/10/excel-inner-join.html
Joins can Left Outer, Right Outer and Full Outer which used in rare ocassions, But we can achieve this for Excel Sheets, For more information check the below
http://exceljoins.blogspot.com/

Excel VBA to transpose set of rows if value exists in another column

I'm trying to find a way via VB script that will transpose rows from column A into a new sheet but only if there is a value in column B for rows that contain numbers. I have a sheet with ~75K rows on it that I need to do this for, and I tried creating pivot tables which allowed me to get the data into its current format but I need the data to be in columns.
The tricky part of this is that in column A, I only need to look at the rows that are all numbers and not the other rows that have text.
I created a sample sheet to view, where the sample data is in the SOURCE tab and what I want the data to look like in the TRANSPOSED tab.
https://docs.google.com/spreadsheets/d/1ujbaouZFqiPw0DbO78PCnz25OY2ugF1HtUqMg_J7KeI/edit?usp=sharing
Any help would be appreciated.
UPDATE and Answer:
I modified my approach and went back to the original source data which was not part of a pivot table and was able to use a simple match formula between the 2 data sources. So, my original data looked like this:
+----------------+---------+--------+--------------+
| Gtin | Brand | Name | TaxonomyText |
+----------------+---------+--------+--------------+
| 00030085075605 | brand 1 | name 1 | cat1 |
| 00041100015112 | brand 2 | name 2 | cat2 |
| 00041100015099 | brand 3 | name 3 | cat3 |
| 00030085075608 | brand 4 | name 4 | cat4 |
+----------------+---------+--------+--------------+
I had another sheet containing the data I needed to match to in this format:
+----------------+---------+
| Gtin | Brand |
+----------------+---------+
| 00030085075605 | brand 1 |
| 00041100015112 | brand 2 |
| 00041100015098 | brand 3 |
| 00030085075608 | brand 4 |
+----------------+---------+
I created a new column in my source sheet and used a if error match formula:
=IFERROR(IF(MATCH(A14,data_to_match!$A:$A,0),"yes",),"no")
Then copied this formula down for every row, about 75K rows which very quickly added a yes or a no.
+----------------+---------+---------+--------+--------------+
| Gtin | matched | Brand | Name | TaxonomyText |
+----------------+---------+---------+--------+--------------+
| 00030085075605 | yes | brand 1 | name 1 | cat1 |
| 00041100015112 | yes | brand 2 | name 2 | cat2 |
| 00041100015098 | no | brand 3 | name 3 | cat3 |
| 00030085075608 | yes | brand 4 | name 4 | cat4 |
+----------------+---------+---------+--------+--------------+
The final step was to just filter for Yes values and I had all the data that I needed.
My mistake was going to a pivot table first which put the data in a very funky format causing me to have to do a transpose, which wasn't really necessary. Hopefully this can help others....

Combine column x to n in OpenRefine

I have a table with an unknown number of columns, and I need to combine all columns after a certain point. Consider the following:
| A | B | C | D | E |
|----|----|---|---|---|
| 24 | 25 | 7 | | |
| 12 | 3 | 4 | | |
| 5 | 5 | 5 | 5 | |
Columns A-C are known, and the information in them correct. But column D to N (an unknown number of columns starting with D) needs to be combined as they are all parts of the same string. How can I combine an unknown number of columns in OpenRefine?
As some columns may have empty cells (the string may be of various lengths) I also need to disregard empty cells.
There is a two step approach to this that should work for you.
From the first column you want to merge (Col D in this case) choose Transpose->Transpose cells across columns into rows
You will be asked to set some options. You'll want to choose 'From Column' D and 'To Column' N. Then choose to transpose into One Column, assign a name to that column, make sure the option to 'Ignore Blank Cells' is checked (should be checked by default. Then click Transpose.
You'll get the values that were previously in cols D-N appearing in rows. e.g.
| A | B | C | D | E | F |
|----|----|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 |
Transposes to:
| A | B | C | new |
|----|----|---|-----|
| 1 | 2 | 3 | 4 |
| | | | 5 |
| | | | 6 |
You can then use the dropdown menu from the head of the 'new' column to choose
Edit cells->Join multi-value cells
You'll be asked what character you want to use to separate the characters in the joined cell. Probably in your use case you can delete the joining character and combine the cells without any joining characters. This will give you:
| A | B | C | new |
|----|----|---|-----|
| 1 | 2 | 3 | 456 |

Calculate the difference between two non-adjacent columns, based on a "match column" using Excel VBA

I'm looking for the most efficient way to compare two sets of two columns, thus:
Set 1:
A | B | C |
11_22 | 10 | |
33_44 | 20 | |
55_66 | 30 | |
77_88 | 40 | |
99_00 | 50 | |
Set 2:
J | K |
33_44 | 19 |
99_00 | 47 |
77_88 | 40 |
For each match between column A and J, column C should display the difference between the adjacent cells
(in this case 33_44, 99_00, and 77_88) in B and K, respectively, with the full
amount in column B if no match exists in J
A | B | C
11_22 | 10 | 10
33_44 | 20 | 1
55_66 | 30 | 30
77_88 | 40 | 0
99_00 | 50 | 3
I'm thinking of creating two multi-dimensional arrays containing values
in the ranges (A, B) and (J, K), with a nested loop, but am not sure how to
get the result back into column C when a match occurs. Creating a third "result array" and outputting that on a fresh sheet would work too.
It is possible to do a lot with ADO, for example: Excel VBA to match and line up rows