Dynamic cell and sorting

Polanskiman

Board Regular
Joined
Nov 29, 2011
Messages
119
Office Version
  1. 365
  2. 2016
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
  2. MacOS
  3. Mobile
So here is the deal. I need that cell in E4 to be dynamic because the "Description" column on the Excel table is supposed to be sortable. By dynamic I mean that no matter the order of the Excel table, cell E4 should always report the correct tag associated to the description. How can I achieve that?

Any help would be appreciated.

Thank you.

Book1.xlsx
BCDEFGHI
1
2In Sheet 1In Sheet 2In Sheet 3
3
4Product 1Product 1 newDescriptionTag
5Product 2Product 1new
6Product 3Product 2old **
7Product 4Product 3used
8Product 5Product 4
9Product 6Product 5
10Product 6new
11Product 7
12Product 8
13
Sheet2
Cell Formulas
RangeFormula
E4E4=Sheet2!C4&" "&Sheet2!H5
 
maybe
In Sheet 1In sheet 2In Sheet 3
ProductDescriptionValueDescriptionTagValue
Product 1Product 1 new2Product 86
Product 2Product 2 old **5Product 71
Product 3Product 3 used8Product 6new0
Product 4Product 41Product 56
Product 5Product 56Product 41
Product 6Product 6 new0Product 3used8
Product 7Product 71Product 2old **5
Product 8Product 86Product 1new2
Custom Product H5
Custom Product D1
Custom Product A5

Power Query:
let
    tbl1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tbl2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Join = Table.NestedJoin(tbl1,{"Product"},tbl2,{"Description"},"Table",JoinKind.Inner),
    Expand = Table.ExpandTableColumn(Join, "Table", {"Tag", "Value"}, {"Tag", "Value"}),
    Merge = Table.CombineColumns(Expand,{"Product", "Tag"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Description"),
    Sort = Table.Sort(Merge,{{"Description", Order.Ascending}})
in
    Sort

Never used Power Query. Let me got get a cold compress first, lay down and come back when my fever is down.o_O
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Upvote 0
Try this in Sheet2. My formula in col E, your same one in col F.

Cell Formulas
RangeFormula
E5:E12E5=VLOOKUP(Sheet1!C5&" *",Table1[Description],1,0)
F5:F12F5=INDEX(Table1[mg/week],MATCH(E5,Table1[Description],0))
Ahh thank you. We are getting there. Seems to be working now (partially). Again because of me sorry.... I just didn't forsee it as a problem, but some cells in Table1 of Sheet 3 sometimes are referring to the same cells in Sheet 1. Example below see yellow cells. How would I adjust the VLOOKUP formula in Sheet 2?

Book1.xlsx
CDE
5DescriptionTagmg/week
6Custom Product A(every day)5
7Custom Product D1
8Custom Product H5
9Fertilizer 1 (4ml/5times week)(4ml/5times week)2
10Fertilizer 1 (2ml/3times week)(2ml/3times week)5
11Fertilizer 3 8
12Fertilizer 4 1
13Fertilizer 5 6
14Fertilizer 6 (once day)(once day)0
15Fertilizer 7 (zoby)(zoby)1
16Fertilizer 8 6
Sheet3
Cell Formulas
RangeFormula
C9,C11:C16C9=Sheet1!C5&" "&[@Tag]
C10C10=Sheet1!C5&" "&[@Tag]
 
Upvote 0
the same code as in post#9 :)
ProductDescriptionValueDescriptionTagValue
Product 8Product 1 new2Product 3used8
Product 7Product 1 other1Product 86
Product 6Product 2 old **5Product 56
Product 5Product 3 used8Product 2old **5
Product 4Product 41Custom Product H5
Product 3Product 56Custom Product A5
Product 2Product 6 new0Product 1new2
Product 1Product 71Product 1other1
Product 86Product 41
Custom Product D1
Product 6new0
Product 71
 
Upvote 0
With that example, what is in Sheet1 (has that changed too?) and what results do you want in Sheet2?
Sheet 1 hasn't changed. It's just that sometime in Table 1 of Sheet 3 some cells will pick up the same cells in Sheet 1.

The result in Sheet 2 is working as it should except if the same cell is referenced twice in Table 1. Here is what happens in the example we are working on:

Cell Formulas
RangeFormula
E5,E7:E12E5=VLOOKUP(Sheet1!C5&" *",Table1[Description],1,0)
F5:F12F5=INDEX(Table1[mg/week],MATCH(E5,Table1[Description],0))
E6E6=VLOOKUP(Sheet1!C5&" *",Table1[Description],1,0)


As you can see VLOOKUP is picking up twice the same thing when in fact if you look at Sheet 3 although there are 2 "Fertilizer 1", both have different tags.

Book1.xlsx
CDE
5DescriptionTagmg/week
6Custom Product A(every day)5
7Custom Product D1
8Custom Product H5
9Fertilizer 1 (4ml/5times week)(4ml/5times week)2
10Fertilizer 1 (2ml/3times week)(2ml/3times week)5
11Fertilizer 3 8
12Fertilizer 4 1
13Fertilizer 5 6
14Fertilizer 6 (once day)(once day)0
15Fertilizer 7 (zoby)(zoby)1
16Fertilizer 8 6
Sheet3
Cell Formulas
RangeFormula
C9,C11:C16C9=Sheet1!C5&" "&[@Tag]
C10C10=Sheet1!C5&" "&[@Tag]
 
Upvote 0
So why are any of the formulas on Sheet2 looking at Sheet1 if they are not using that list?
For example, Sheet1 still has "Fertilizer 2" yet you are apparently ignoring that one in Sheet2?
Can you put in words, how you decide what goes in Sheet2 column E?

Is a formula solution that works in Excel 365 but not Excel 2016 acceptable?
In your Excel 365, do you have ..
- the SORTBY function?
- the LET function?
 
Upvote 0
I will try my best to explain:
What I am building is a calculator for fertilizers.
Sheet 1: This sheet contains commercial fertilizer names. This is a setting sheet where the user input fertilizer price, volume among other data. Fertilizer names already hardcoded there and the user does not input any new fertilizer names. This is the source for fertilizer names across all other sheets.
Sheet 2: This sheet is a sheet that basically regroups prices of all fertilizers, weekly cost according to users' use of the product etc. This sheet is meant to be seen by the user but no interaction or input is required by the user. It's purely informational.
Sheet 3: This is the backbone of the calculator. Everything is calculated here (prices, mg, ppm, you name it). This is an Excel Table solely aimed at calculating stuff but it's not meant to be seen by the end user but it is seen by people currently working on it. Sheet will be hidden.

There are several other user sheets where the user sets his fertiliser dosing etc etc etc, but my problem lays between these 3. Well more precisely with Sheet 2. The reason of my request is that I want to make things foolproof. As it currently is (before I posted here) everything is "working fine". The only problem is that if for some reason the Excel Table in sheet 3 is sorted then all goes to hell in sheet 2 for a few fertilizers because of the tag column attached to them. I want to avoid this screw up.

So why are any of the formulas on Sheet2 looking at Sheet1 if they are not using that list?
Sheet2 is simply picking up the names of the fertilizers. Some fertilizers need to be duplicated because they may have different dosing regimes, hence the tag column to differentiate them.

For example, Sheet1 still has "Fertilizer 2" yet you are apparently ignoring that one in Sheet2?
I am not ignoring it. It was there before but because of the issue I mentioned in post #14 I edited Fertilizer 2 to show that sometimes I have twice the same fertilizer name in that table. "Fertilizer 2" will also be in the table.

Can you put in words, how you decide what goes in Sheet2 column E?
All fertilizers names in Sheet 2 are coming from Sheet 1. They are all there. It's just that some need to be duplicated because in Sheets 3 were all the calculations are done, some of the fertilizers need to duplicated.

Is a formula solution that works in Excel 365 but not Excel 2016 acceptable?
In your Excel 365, do you have ..
- the SORTBY function?
- the LET function?
I would like this to be the most backward compatible as possible, because the file will be distributed publicly, so anything that is working only with 365 might not be a good solution. Yes both functions are present in my Excel.

Thank you. Hopefully this explains better.
 
Upvote 0
My suggestion would be this.
  • Since end user does not see Sheet3 and this whole sheet is about fertilizers, I would include a column in your table for fertilizer name, like you had in post 1. That column may be useful for people working on the table too.
  • Notice a change in the Description column formula in the table too.
  • Also include a helper column in the table as shown below. If you want, this column could be hidden once you have entered the formula.
  • Sheet 2 could then draw all the information from the table, without reference back to Sheet1.

Original order for table
Cell Formulas
RangeFormula
C6,C8:C13C6=Sheet1!C5
C7C7=Sheet1!C5
D6:D16D6=[@Fertilizer]&" "&[@Tag]
G6:G16G6=MATCH([@Fertilizer],Sheet1!C$5:C$12,0)+COUNTIF(INDEX([Fertilizer],1):[@Fertilizer],[@Fertilizer])/10^6


Results:
Cell Formulas
RangeFormula
E5:E14E5=IFERROR(INDEX(Table1[Description],MATCH(AGGREGATE(15,6,Table1[Idx],ROWS(A$1:A1)),Table1[Idx],0)),"")
F5:F14F5=IF(E5="","",INDEX(Table1[mg/week],MATCH(E5,Table1[Description],0)))


Re-order table:
Cell Formulas
RangeFormula
C6C6=Sheet1!C10
C7C7=Sheet1!C8
C8C8=Sheet1!C11
C10,C14C10=Sheet1!C5
C11C11=Sheet1!C5
D6:D16D6=[@Fertilizer]&" "&[@Tag]
C15C15=Sheet1!C12
C16C16=Sheet1!C7
G6:G16G6=MATCH([@Fertilizer],Sheet1!C$5:C$12,0)+COUNTIF(INDEX([Fertilizer],1):[@Fertilizer],[@Fertilizer])/10^6


Results:
Cell Formulas
RangeFormula
E5:E14E5=IFERROR(INDEX(Table1[Description],MATCH(AGGREGATE(15,6,Table1[Idx],ROWS(A$1:A1)),Table1[Idx],0)),"")
F5:F14F5=IF(E5="","",INDEX(Table1[mg/week],MATCH(E5,Table1[Description],0)))
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top