Using of INDIRECT formula in many ranges - excel

I'm standard excel user (I know only record macro :)), but I really need your help, I'm lost. I'll try to describe what I need to do.
I'm trying to apply limited drop-downs based on previous selection. Please find the picture:
Data (columns A, B)
Dropdowns (G, H)
What I need is, that the user select some, concrete Company in column G. He will have limited drop-down in H column. So everything, what I need, is using INDIRECT formula through the Data Validation (menu - Data), but for this I need to get name to every range in column B, which will be available (for same Company), so the name of these ranges have to have exact name for each Company (a, b, c ...etc.).
The problem is that I have hundreds Companies. Do you have some idea, how can I proceed macro which allocate these names to all ranges in B column with names as per A column?
If you have any other idea how I can solve this, it will be sufficient for me too.
Thanks.
Franta

The better approach here is to use OFFSET for the Data Validation List formula.
In H2 apply Data Validation List using
=OFFSET($B$1,MATCH($G2,$A:$A,0)-1,,COUNTIFS($A:$A,$G2),1)
What this does is:
Finds the row containing the first instance of company in column A (MATCH($G2,$A:$A,0))
Counts the number of instances of company in column A (COUNTIFS($A:$A,$G2))
Creates a range offset from B1 by the Row match -1, and resizes it to the count of company
That's the range used by Validation
Note: this relies on the companies being sorted as shown in your sample data

Related

Excel: Is it possible to have a running two column list on one page and have it transfer to a secondary tab?

I have a database tab which holds all my information for each item in my inventory. This is always changing as I add new inventory. I want to take certain information in that tab (columns A & B) and use it in a separate tab called stock inventory in columns A & B. When it transfers I would like a blank cells in columns C,D,E, and F. I did try VLOOKUP however, because column A on the database tab is repeated, when the information was transferred to the stock inventory tab it duplicated information instead of actual information. For example Column A may say "Scale" column B may say "abalone, there may be a second entry with the same information in column A but different information in column B. When it transfers to the stock inventory tab anytime it recognizes "scale" in the column A it would say Abalone. This is not what I want. I want to bring over actual information for column B even if column A is the same. Any help is appreciated.
To solve the problem of the repeated value in the VLOOKUP you could create helper column on the left of the first vlookup matrix column, with the formula =ROW()&A2, and use this value as key to be searched with vllokup instead of the value in A1: there will be no duplicates, as the value will be the concatenation of the row number and the name of the article.

How to count unique column data in an excel sheet

I am using excel sheet and i have data column as shown below:
As we can see that some of the names are duplicate or appeared twice. My question is how can count unique name records or rows associated with each name for summary column.
Out put i am looking for is shown below:
Not sure which formula to use as count is counting all of that data i.e. '7' in this case. How can i use count or any other function to count unique records as shown above?
You can do what you're after with a pivot table.
Click the Insert tab then select "Recommended Pivot Tables".
A window will open up prompting you to select the data range. I recommend using a named range for your list and referencing that, but you can just highlight the list directly if you want.
Once the data range is selected, click "Ok" and new window will open with exactly what you want. A unique values list and a "Count of Column1". It is the default of the recommended pivot tables.
I outlined this because it's easy and fast, but it's important to understand you can make this pivot table yourself from scratch if you learn about pivot tables in general. Pivot tables are often overlooked in Excel as an option.
Lastly, you could get really advanced with Excel Power Queries. Just Google "Excel Power query" and you will be shown all kinds of information on them. They are a close second place in power to manipulate Excel data short of using VBA.
Good luck!
CountA(Unique(D2:D8,,False)) = 5 [Count(Unique(D2:D8)) is the same as False is the default.]
CountA(Unique(D2:D8,,True)) = 3 (once and only once)
Note: the Unique function was released in late 2019 to Office 365. So if you want to use this check your version, not present in 1908, present in 2006.
Edit: It's actually in 2002, I just updated my 1908 machine.
HTH
If names duplicates are removed the following formula can be used: =COUNTIF(B:B,F2)
If duplicates must be removed by formula, MATCH (searches for a specified item in a range of cells, and then returns the relative position of that item in the range.) and SMALL (Returns the k-th smallest value in a data set.) functions can be used as shown.
C$1048576 is used to reference last row number for a big list case.
formulas:
Column A, names sequence
Colunm B, names
Column C, formula =MATCH(B2,B:B,0)
Column D, formula =IF(COUNTIF(C2:$C$1048576,C2)=1,C2,"")
Column E, formula =SMALL(D:D,A2)
Column F, formula =VLOOKUP(E2,A:B,2,0)
Column G, formula =COUNTIF(B:B,F2)
For anyone like me without O265's lovely Unique & Filter Functions, and who doesnt want to use a pivot table, and there are many ways to do this, but this i have just done this in normal excel.
List of data in Column H, Formula in column O3. Drag down. Highlights your distinct and unique values from H.
=IF(COUNTIF(H:H,H28)=1,"U - "&COUNTIF(H:H,H28),IF(COUNTIF(H$1:H27,H28)=1,"U - "&COUNTIF(H:H,H28),"-"))
Formula is short. You can just do this and drag down. Apply the same principal to your worksheet data wherever it is.
=IF(COUNTIF(H:H,H3)=1,"U",IF(COUNTIF(H$1:H2,H3)=1,"U","-"))
Similarly, you can just use this formula here (credit goes to this source for this one):
=(COUNTIF($H$1:$H1,$H1)=1)+0
Id like to point out that the above formula is a better formula than mine. It highlights with a "1" (or with a tweak, the value of your choice) the first time any value is seen/spotted on any given list, whether duplicate or unique.
Whereas mine is a bit "more random" when picking up the "unique and distict" values.
Mine gets there in the end, but Extend Office's gets there first, as I think is proper (getting the first time a unqique distict value is spotted/occurs.).
Formula in K5 =IF((COUNTIF($H$5:$H5,$H5)=1)+0=1,"UNIQUE DIST","") and drag down...
You could append/add a normal basic countif after the results to show how many actual times the given value appears if you wanted. :
=IF((COUNTIF($H$5:$H5,$H5)=1)+0=1,"UNIQUE DIST","")&" - "&COUNTIF(H:H,H5)

VBA code required to loop through different sized rows of data and return MAX value

I am currently automating a dashboard creation and I've hit a bit of a roadblock. I need some code that will go through about 7000 rows of data and return the highest value in a certain column for each specific item. The data is copied from a pivot table and so is broken down into row sections, I have attached a mock of what it looks like.
I need the highest value in Column G for each portfolio, and will need to use the portfolio code (e.g. XY12345 - They are always 7 characters) to map that value to the dashboard.
My issue is, each portfolio has a different number of rows for the values, and some have blank cells between them, and therefore I am stumped. I was hoping to use Column J to count the number of rows for each portfolio (as there are no breaks for the portfolios in this column) and then use a loop to loop through each portfolios rows of values, based off the Column J count, and then return the highest row value for each portfolio. Problem is I'm new to VBA and have been teaching myself as I go, and I've yet to use a loop.
Many thanks,
Harry
If I understand correctly, you're looking for the largest value in Column G.
I'm not sure why you think you would need VBA for this.
Get the maximum value of a column
You mentioned that you're concerned about each column not having the same number of cells but that's irrelevant. as SUM ignores blank cells, so just "go long", or - find the maximum of the entire column.
To return the largest number in Column G you could use worksheet formula :
=MAX(G:G)
The only catch is that you can't place that formula anywhere column G or else it would create a circular cell reference (trying to infinitely add a number to itself). let's pit that formula in cell F1 for now (but anywhere besides column G would do fine).
Find the location of a value
Now that you know the largest value, you can determine where it is using a lookup function such as MATCH or VLOOKUP. Like with so many things in Excel, there are several ways to accomplish the same thing. I'll go with MATCH.
Replace the formula from above (in F1) with:
=MATCH(MAX(G:G),G:G,0)
This will return the row number of the first exact match of the maximum value of Column G.
As for the third part of question: returning the code like X12345 where the value exists, will be a little tricky since your data is not organized in a logical tabular style (tabular meaning, "like a table").
Your data is organized for humans to look at, not for machines to easily read and manipulate it. (See: Office Support: Guidelines for organizing and formatting data on a worksheet)
Basically, when organizing data in rows, all relevant information should be on the same row (not a subjective number of rows behind). Also, you have the number combined with other information.
My suggestion for a quick fix:
Right-click the heading of Column C and choose Insert to insert a blank column.
In C2 enter formula: =IF(B2="",C1,LEFT(B2,7))
Copy cell C2
Select cells in column C all the way to the "end" of your data, where ever that is (not the end of the worksheet). For example maybe you would select cells B2:B1000)
Paste the copied cell into all those cells.
Now, you can again modify the formula in F1:
=INDEX(C:C,MATCH(MAX(G:G),G:G,0))
This will return the value from Column C in the same row that the maximum value of Column G is located.
This is known as an INDEX/MATCH formula.
Hopefully this works for you in the interim until you can organize your data more logically. There's lots of related information and tutorials online.

Sumif based on multiple criteria and location

I'm trying to use Excel to extract figures based on multiple criteria and their location within columns.
So for example. If I wanted to do a SUMIF to receive the figures associated with the First class. The formula would retrieve the figure in a specified row,
But If I wanted to retrieve the figure associated with England. The formula would contain multiple criteria to look for the First class then look for the country England and retrieve the figure on its row in a specified column.
These columns will grow and shrink each month. Meaning I need it to be somewhat dynamic.
I've tried to do this using SUMIF and SUMIFS with no luck.
=SUMIFS(D2:D10,A2:A10,"First",B2:B10,"England")
The challenge you have is that in columns A, B and C, the values are not repeated downwards into the now blank cells. So values do not appear next to each other in the same row.
Assuming that the example you gave is quite simple, and you could also have multiple International Products for a given Class and Country, I would go for the following solution:
Reserve two columns (E and F) for intermediate calculations. If they are currently used, move those used columns to the right, making room for an empty E and F column. You could of course also choose two other columns for this purpose. But I will assume they are E and F.
Then in E2 put this formula and copy it further down the E column as far as needed.
=IF(A2<>"", A2, OFFSET(E2,-1,0))
In F2 put this formula and copy it down as well:
=IF(B2<>"", B2, IF(A2<>"", "", OFFSET(F2,-1,0)))
This should give the following display (the header titles in E1 and F1 are cosmetic only):
Now you can do formulas on those columns in combination with the C column. For instance:
=SUMIFS(D2:D10, E2:E10,"First", F2:F10,"England", C2:C10,"")
And this would output 2. Note that if you really only want to match one row, you should specify a condition for each column (E, F and C).
The intermediate formulas in the E and F columns are quite resistant to deletion of rows, due to the use of OFFSET. If you insert rows, you should of course make sure the formulas in E and F are copied into it.
If you will ever use more than 3 columns for the source data, you'll need to also add more intermediate columns with similar formulas. Also your SUMIFS would need extra conditions then.
You could use the following SUMPRODUCT() For Class and Country:
=SUMPRODUCT(($A$2:$A$10=$F$1)*($B$3:$B$11=$G$1)*($D$3:$D$11))
Then for all three:
=SUMPRODUCT(($A$2:$A$10=$F$1)*($B$3:$B$11=$G$1)*($C$4:$C$12=H1)*($D$4:$D$12))
A picture for references.
The idea is that each column must move down one row in its reference. And the Sum column must start on the same row as the last column being referenced.

excel, without script, just using its built in features, how to trigger a value or content in one cell based on value or content in other cell

Need advice on the following; Thanks in advance.:
Excel, the visual description of the issue
Further description of the issue:
certain Product code = certain Product name of certain Size.
The help-table on the attached image shows that a certain product code = what product name of what size, as a guide.
This is what I try to do. This is what my question is: How to achieve:
Manual entry in cells of column A should trigger automatically filled content in cells of columns B and C based on the content of A and based on the dependencies described in the help-Table.
Edited: As the user proceeds adding new records in new rows, the appropriate columns (B and C) should "fill itself" automatically as soon as there's an entry in the same row in column A. This automatically filled content in column C and B depends on what is the content of column A as can be seen on the attached image("help-table"). And all this should work without me using a formula in columns B and C.
So far I used an "IF" formula which is not practical for many possible product codes.
A formula is also impractical as its usage requires the formula to be copied to next row, which I want to avoid. I want the set rule to be applied to a whole column.(for example as the data validation or conditional formatting work in excel)
It would be ideal to use it in a way like the conditional formatting works, but in this case it should work with values(content) instead of colors and should be applicable for an entire column without a need of copying to the next row. That means I'd like to avoid macros or VBA if possible, just want to use built in features.
I already use Defined names and Data validation for columns A,B and C which works for me as a choice list and also to control column B and C for allowed entries only, so their content is not mistyped and has the strict format needed. Excel 2010 -if that matters.
Important: there will be 1000's of rows added, I just made a short description above
Formula for cells in column B:
=IF(A2=10,"prod1",IF(A2=20,"prod1",IF(A2=30,"prod2",IF(A2=40,"prod2",""))))
Formula for cells in column C:
=IF(A2=10,"50",IF(A2=20,"75",IF(A2=30,"10",IF(A2=40,"50",""))))
Also tried a CSE formula for the entire column B or C like follows (but the file size was couple of MB which is not desired):
=IF(A:A=10,"prod1",IF(A:A=20,"prod1",IF(A:A=30,"prod2",IF(A:A=40,"prod2",""))))
If the entry in column A will be only 10,20,30 and 40 then use OR formula in column B
=IF(OR(A2=10,A2=20),"prod1","prod2")
In Column C we can reduce two IF
=IF(A2=20,"75",IF(A2=30,"10","50"))
And regarding the file size please save it in binary format. Hope this will help :)

Resources