Col A,Col B,Col C
Test1,Test1,Test3
Test2,Test1,Test3
Is there a way to go thru all cells and pick out the unique values and place them in a new column or something?
Most of the answers on Getting unique values in Excel by using formulas only only work for values in a single column.
For a solution that works for values in multiple rows and columns, I found the following formula very useful, from http://www.get-digital-help.com/2009/03/16/unique-values-from-multiple-columns-using-array-formulas/
Oscar at get-digital.help.com even goes through it step-by-step and with a visualized example.
1) Give the range of values the label tbl_text
2) Apply the following array formula with CTRL + SHIFT + ENTER, to cell B13 in this case. Change $B$12:B12 to refer to the cell above the cell you enter this formula into.
=INDEX(tbl_text, MIN(IF(COUNTIF($B$12:B12, tbl_text)=0, ROW(tbl_text)-MIN(ROW(tbl_text))+1)), MATCH(0, COUNTIF($B$12:B12, INDEX(tbl_text, MIN(IF(COUNTIF($B$12:B12, tbl_text)=0, ROW(tbl_text)-MIN(ROW(tbl_text))+1)), , 1)), 0), 1)
3) Copy/drag down until you get N/A's.
If you are using Excel 2007 at least, then you can just use Remove Duplicates function from Data tab.
Otherwise I think a little bit of VBA fairy dust sprinkling is in order. I can mash up a quick VBA script if you need it.
Related
I have data in following pattern:
I want a formula to get the data between Content Start and Content End. The amount of content between the start and end is not just limited to 4 and can change.
You don't say what you want to do with this result.
I am assuming you can code the column in which your data is located.
The formula below will return those values as an array. e.g. with your data, the formula will return {1;2;3;4}
The values could be numeric or text.
How you want to handle those values is up to you.
=INDEX($A:$A,N(IF(1,ROW(INDEX($A:$A,MATCH("Content Start",$A:$A,0)+1,1):INDEX($A:$A,MATCH("Content End",$A:$A,0)-1,1)))))
EDIT: Here is an example of using that information to create a sparkline. In this example, the formula above has been wrapped in TRANSPOSE and entered as an array formula in C1:I1. The Sparkline has been entered in B1. As with most charts, Excel is ignoring the #N/A errors.
And here is an example where the sparkline is in A1 and the transposed array is somewhere else, not in view, on the worksheet:
With Worksheets("Your Sheet").Range("A:A")
Set c = .Find("Content Start", LookIn:=xlValues)
Set d = .Find("Content End", LookIn:=xlValues)
ActiveSheet.Range(Cells(c.Row + 1, c.Column), Cells(d.Row - 1, c.Column)).Select
End With
Probably multiple ways doing this, but if you prefer to do it without VBA you could use:
Formula used in B1 (allthough a bit lengthy):
{=INDEX($A$1:$A$10,SMALL((ROW($A$1:$A$10)>MATCH("Content Start",$A$1:$A$10,0))*(ROW($A$1:$A$10)<MATCH("Content End",$A$1:$A$10,0))*ROW($A$1:$A$10),SUM((ROW($A$1:$A$10)>MATCH("Content Start",$A$1:$A$10,0))*(ROW($A$1:$A$10)<MATCH("Content End",$A$1:$A$10,0)))+ROW(A3)))}
Notice it's an array formula entered through CtrlShiftEnter
Drag down....
Please see below
I want to concatenate 'comments' in table 2 into table 1 as shown in the series of images without using TEXTJOIN() or macros. Only using regular excel functions
There is no simple solution without using UDF or helper columns. I would suggest using UDF formula which is simple to implement and use in worksheets. To use this approach, please enter this code in your regular module(module1).
Function Lookup_concat(Search_string As String, _
Search_in_col As Range, Return_val_col As Range)
Dim i As Long
Dim result As String
For i = 1 To Search_in_col.Count
If Search_in_col.Cells(i, 1) = Search_string Then
result = result & " " & Return_val_col.Cells(i, 1).Value
End If
Next
Lookup_concat = Trim(result)
End Function
now you can use this UDF just like regular worksheet formula. Enter this formula =Lookup_concat(G3,$D$3:$D$12,$E$3:$E$12) in cell I3 and drag it to the bottom.
in case you want to use only regular formulas, you will need to enter this formula =IFERROR(INDEX($D$3:$E$12, SMALL(IF(($G3=$D$3:$D$12), ROW($D$3:$D$12)-MIN(ROW($D$3:$D$12))+1, ""),COLUMNS($A$1:A1)), 2),"") in cell K3 using CTRL+SHIFT+ENTER combination since it is an array formula. Now drag formmula to the right and down(Estimate how far to the righ your formula needs to go in order to catch all unique values).
Then enter this formula =CONCATENATE(K3," ",L3," ",M3," ",N3," ",O3," ") in cell J3 and drag it to the bottom (adjust formula to estimated number of unique values).
There's a simple way to do this. :) Please see this Google sheet for a working example.
You can use the FILTER and JOIN functions to achieve this:
=iferror(join(", ", filter(E$3:E$12, D$3:D$12 = G3)))
In the above example the FILTER function will look at cells D3:D12 and try to find rows matching the value in G3. For the matching rows, the FILTER function returns the values from cells E3:E12 as an array.
JOIN is used to join the array items together with a comma in between.
Finally, IFERROR gets rid of N/A errors resulting from FILTER not matching anything.
(Kudos to original answer here https://stackoverflow.com/a/23367059/36817)
You will need to add a helper column to achieve your goal.
Assuming you have the helper column C and this is the array formula (means you have to click Ctrl + Shift + Enter altogether) you should try:
{=IF(OR(ROW(C1)=1,MAX(--($A$1:A1=A2)*ROW($A$1:A1))=0),B2,INDEX($C$1:C1,MAX(--($A$1:A1=A2)*ROW($A$1:A1)))&", "&B2)}
Now at column G assuming this is the place you want to get your outcome, you can enter this array formula (means you have to click Ctrl + Shift + Enter altogether):
{=IFERROR(INDEX($A$2:$C$11,MAX(--($A$2:$A$11=E2)*ROW($A$2:$A$11))-1,3),"")}
This way you should get the results you are expecting.
In a spreadsheet I use for cash management tracking, I have the following formula:
=IF(D176="Cash", F175+C176, IF(D176="Transfer", F175+C176, F175))
When I add a row, I use control+D to fill in the formula from the cell above (I'm using Excel for Mac 2011). This results in the correct formula as follows:
=IF(D177="Cash", F176+C177, IF(D177="Transfer", F176+C177, F176))
However, this has the effect of changing the formula in the cell in the row below:
=IF(D178="Cash", F176+C178, IF(D178="Transfer", F176+C178, F176))
Here you can see the rows for column F are not correct: F176 should be F177.
Can anyone offer any advice to ensure that when I insert a row the formula remains intact?
Thanks.
Replace all of the references to F175 in the original formula (the one if row 176) with INDEX(F:F, ROW()-1).
=IF(D176="Cash", INDEX(F:F, ROW()-1)+C176, IF(D176="Transfer", INDEX(F:F, ROW()-1)+C176, INDEX(F:F, ROW()-1)))
'or better as
=INDEX(F:F, ROW()-1)+(OR(D176={"Cash", "Transfer"}*C176)
i have two sheets raw Data and Summary. i need help in editing below formula which i am using in my VBA code. i am looking for sum of one particular id for multiple conditions. in summary unique ids and i already have this formula which is working fine
=SUMPRODUCT(('Raw Data'!$A$2:$A$3457=A2)*('Raw Data'!$D$2:$D$3457={"HAUD","AANZ","CSHK","HCNY","CHN1,CHN2","IN1","DBIN","CSJL","CTOK","BTK","K01","MYFM","MYPB","HNZD","BNZD","PKDB","HSBP","SCS","SCTW","SCT","SCT"})*('Raw Data'!$F$2:$F$3457="BLF")*('Raw Data'!$G$2:$G$3457))
sum in "G" column sholud also include cells in D column which begins with "TW" or "K"
i tried this but its not working
=SUMPRODUCT(('Raw Data'!$A$2:$A$3457=A2)*(LEFT('Raw Data'!$D$2:$D$3457,2)="TW"))*(LEFT('Raw Data'!$D$2:$D$3457,2)="K"))*('Raw Data'!$D$2:$D$3457={"HAUD","AANZ","CSHK","HCNY","CHN1, CHN2","IN1","DBIN","CSJL","CTOK","BTK","K01","MYFM","MYPB","HNZD","BNZD","PKDB","HSBP","SCS","SCTW","SCT","SCT"})*('Raw Data'!$F$2:$F$3457="BLF")*('Raw Data'!$G$2:$G$3457)
your assistance highly appreciated
below one is also tried it shows blank all "," are replaced with * still shows Blank
=SUMPRODUCT('Raw Data'!$G$2:$G$3457,--('Raw Data'!$A$2:$A$3457=A2),(LEFT('Raw Data'!$D$2:$D$3457,2)="TW")+(LEFT('Raw Data'!$D$2:$D$3457,1)="K"),--ISNUMBER(MATCH('Raw Data'!$D$2:$D$3457,{"HAUD","AANZ","CSHK","HCNY","CHN1","CHN2","IN1","DBIN","CSJL","CTOK","BTK","K01","MYFM","MYPB","HNZD","BNZD","PKDB","HSBP","SCS","SCTW","SCT","SCT"},0)),--('Raw Data'!$F$2:$F$3457="BLF"))
I believe that the first formula should be more like:
=SUMPRODUCT(('Raw Data'!$A$2:$A$3457=A2)*('Raw Data'!$D$2:$D$3457={"HAUD","AANZ","CSHK","HCNY","CHN1","CHN2","IN1","DBIN","CSJL","CTOK","BTK","K01","MYFM","MYPB","HNZD","BNZD","PKDB","HSBP","SCS","SCTW","SCT","SCT"})*('Raw Data'!$F$2:$F$3457="BLF")*('Raw Data'!$G$2:$G$3457)*((LEFT('Raw Data'!$D$2:$D$3457,2)="TW")+(LEFT('Raw Data'!$D$2:$D$3457,1)="K")))
There was no quotes in "CHN1,CHN2" in both the first and the working formula that I added. I also changed
(LEFT('Raw Data'!$D$2:$D$3457,2)="TW"))*(LEFT('Raw Data'!$D$2:$D$3457,2)="K"))
to
((LEFT('Raw Data'!$D$2:$D$3457,2)="TW")+(LEFT('Raw Data'!$D$2:$D$3457,1)="K"))
The last one should work if you change the , in the array to ; (to mean a vertical array):
=SUMPRODUCT('Raw Data'!$G$2:$G$3457,--('Raw Data'!$A$2:$A$3457=A2),(LEFT('Raw Data'!$D$2:$D$3457,2)="TW")+(LEFT('Raw Data'!$D$2:$D$3457,1)="K"),--ISNUMBER(MATCH('Raw Data'!$D$2:$D$3457,{"HAUD";"AANZ";"CSHK";"HCNY";"CHN1";"CHN2";"IN1";"DBIN";"CSJL";"CTOK";"BTK";"K01";"MYFM";"MYPB";"HNZD";"BNZD";"PKDB";"HSBP";"SCS";"SCTW";"SCT";"SCT"},0)),--('Raw Data'!$F$2:$F$3457="BLF"))
I'm not sure if this is even possible without going to VB, but I was trying to do it through conditional formatting. Basically I have a column (Column K) that will always be the same value (345) if there is a record entered in that row. Basically when I populate my reports I simply want the value (345) to be entered into Column K if there is any data in that row. I was trying to just use Column A as a reference. I was messing with =IF(ISTEXT(Col.A location),"345","") but that's getting nowhere. So, I'm looking for ideas outside of vba, but if there are no possibilities then vba is the way to go I suppose. :)
Assuming your data is in columns A to J, and that it starts in row 2, enter this in K2 and copy down as necessary:
=IF(COUNTA(A2:J2),345,"")
Edit: For a conditional formatting formula you don't need the "If" part, because the formatting is already ... conditional:
=COUNTA(A2:J2)
Will this work?
=IF(ISBLANK(A1),"","345")
This code works to tell whether column A has something in it or not COUNTA(INDIRECT("$A$"&ROW()))>0, but I don't think you can set the value of the cell using conditional formatting. But with conditional formatting you have to know ahead of time how far down your data is going to go unless you just put it in all the rows.
Why don't you just put it in your VBA code when you are copying, you can find out what the last row is then put the IF() formula in. You can use this code:
Dim r1 As Range
Set r1 = Range("K1")
r1.NumberFormat = "General"
r1 = "=IF(COUNTA(INDIRECT(""$A$""&ROW())>0,""345"","""")"
r1.AutoFill Destination:=Range(r1, r1.Offset(200))