I have a formula to combine several values:
Value in column C
Add 'And' if there is a space
Drop down selection value in column I
Assigned value based on dropdown selection in column I (e.g. B1, C1)
Append B1 or C1 to value in column C, result shown in column M
The formula in column M:
=IF(I15="Truck",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and ","And"),CHAR(32),"")),IF(I15="Bus",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")& "B1"),IF(I15="Car",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")),"")& "C1"))
It works except for one tiny part; whenever the value in column C is blank, C1 is populated into column M by default. The value in column M should be blank.
Any thoughts?
The real issue is when I15 is blank. Run through with the "Evaluate Formula" tool, and you should see it, but if you break your code out and format it with indentations/new lines, etc:
=IF(I15="Truck",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and ","And"), 'Should this be "and" rather than "and " to match the "Bus" and "Car"?
CHAR(32),
""
)
),
IF(I15="Bus",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)& "B1"
),
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
Now, trace through if I15 is blank: I15 is not "Truck" and I15 is not "Bus", so we get:
=IF(FALSE,
N/A,
IF(FALSE,
N/A,
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
Simplify that down, and you get:
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
),
""
)& "C1"
But, I15 is blank, not "Car", so it becomes IF(FALSE, N/A, "") & "C1" - meaning, it will always say "C1" if I15 is not "Bus" or "Truck".
Also, you probably can simplify your code down to =CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")) & IF(I15="Bus", "B1", IF(I15="Car", "C1", ""))
If you can set up a table somewhere, you can change the IF statement to a VLOOKUP, or if you have a table for the Drop-down values you can use CHOOSE(MATCH(..))
Related
I want to extract distinct values from multiple columns.
Example described below :
I have to columns A and B and the desired result is the distinct values between A and B
Use UNIQUE(FILTER()):
=UNIQUE(FILTER(A:B,(A:A<>"")*(B:B<>"")))
Assuming your data is located at [B4:C16] enter this FormulaArray in [E4] then copy to [F4] and [E5:F16]:
= IFERROR( INDEX( B$4:B$16,
MATCH( 1, 1 +
COUNTIFS( $E$3:$E3, $B$4:$B$16, $F$3:$F3, $C$4:$C$16 )
+ ( $B$4:$B$16 = "" ) + ( $C$4:$C$16 = "" ), 0 ) ), "" )
FormulaArray is entered holding down ctrl+shift+enter simultaneously, the formula would be wrapped within { and } if entered correctly.
In Excel 2007, you can use the Advanced Filter
Provide header columns for your data.
I used Country and Year
Set up your criteria range:
A21: Country
A22: <>
B21: Year
B22: <>
Select a cell in your Data range and choose Advanced Filter on the Data tab
In the Advanced Filter dialog
Select Copy to and enter a destination cell in the appropriate area.
Select Unique
In the below Vllokup function.
I want to use a variable instead of using hard-coded value as "No Category"
=IF( ISNA( VLOOKUP(Param)),"No Category", IF(LEN(VLOOKUP(Param)) =0,"", VLOOKUP(Param) ))
I tried like the following way , unfortunately i can't make it.
=IF( ISNA( VLOOKUP(Param))," & VarCategory & ", IF(LEN(VLOOKUP(Param)) =0,"", VLOOKUP(Param) ))
Many Thanks
You can use a cell in your spreadsheet as a search box. For example, say you pick cell A1 as the box that can contain whatever you type into it. Your formula can then say:
=IF( ISNA( VLOOKUP(Param)), A1 , IF(LEN(VLOOKUP(Param)) =0,"", VLOOKUP(Param) ))
Now your VLOOKUP is no longer hard coded. It will look based on whatever is in cell A1.
I need help to write a code to return values for DF using the ID in the lookup table to fetch value that correspond to the latest date where there are duplications
Try a array formula, copy below formula and paste in cell B14 (i'm considering that "DATABASE" are in A1), and press Ctrl + Shift + Enter.
=INDEX(
$D$3:$D$8,
MATCH(
$A14 &
":" &
MAX(
IF(
$A14 = $A$3:$A$8,
$E$3:$E$8,
0
)
),
$A$3:$A$8 &
":" &
$E$3:$E$8,
0
)
)
I have a question regarding excel.
I have two columns, column A has a number and B has country codes. I'm looking for a way to automatically go through 100's thousands of rows to group them so they look like the following...
Is this doable? I'm at a complete loss :(
THE END RESULT
6512 AG,AI,AW,BB,BL,BM,
6513 BQ,BS,BZ,CA,CR
STARTING POINT - column A & B
6512 AG
6512 AI
6512 AW
6512 BB
6512 BL
6512 BM
6513 BQ
6513 BS
6513 BZ
6513 CA
6513 CR
These solutions use a working column named Concatenated Results.
Assuming your data has a header (adjust formulas as required) and is located at B6:C34 (change as required) as in fig below.
Data sorted by ID:
Concatenated Results: Enter this formula in D7.
= CONCATENATE( C7, IF( EXACT( B7, B8 ), "," & D8, "" ) )
ID.Unique: Enter this Array Formula in E7 (FormulaArrays are entered pressing CTRL+SHIFT+ENTER simultaneously, you shall see { and } around the formula if entered correctly)
=IFERROR( INDEX( $B$7:$B$34,
MATCH( 0, COUNTIF( $E6:$E$6, $B$7:$B$34 ), 0 ) * 1 ), "" )
Countries: Enter this formula in F7
=IFERROR(VLOOKUP(E7,$B$6:$J$34,3,0),"")
Copy range D7:F7 till last row of data (i.e. row 34).
Data not sorted: If the data is not sorted enter this formula for the Concatenated Results in D7. All other formulas remain unchanged.
=CONCATENATE( C7,
IF( ISERROR( MATCH( B7, B8:B$35, 0 ) ), "",
"," & VLOOKUP( B7, B8:D$35, 3, 0 ) ) )
Suggest to read the following pages to gain a deeper understanding of the resources used:
Excel functions (alphabetical), Create an array formula, Guidelines and examples of array formulas
Try this out and let me know in case of any queries or if you require detailed explanation.
Step1: Filter the data by column A.
Step2: Make a new column C where use this formula IF(A2=A1,CONCATENATE(B2,",",C1),B2) .
Step3: Make a new column D where use this formula IF(A2=A3," ","REQUIRED_ANS") .
Step4: Filter on column D using ALT + D + F + F and you get you desired output.
My Output:
This is a VBA solution
Assuming your data, excluding header, is located at B7:C34 (change as required).
ID.Unique: Enter this Array Formula in E7 (FormulaArrays are entered pressing CTRL+SHIFT+ENTER simultaneously, you shall see { and } around the formula if entered correctly)
=IFERROR( INDEX( $B$7:$B$34,
MATCH( 0, COUNTIF( $E6:$E$6, $B$7:$B$34 ), 0 ) * 1 ), "" )
Countries: Enter this User Defined Function (UDF) in F7
=Match_Concatenated(E7,$B$7:$C$34)
Copy this UDF code in a VBA Module
Option Explicit
Public Function Match_Concatenated(vValue As Variant, rTrg As Range) As String
Dim sOutput As String
Dim vTrg As Variant, vItm As Variant, lRow As Long
vTrg = rTrg.Value2
For lRow = 1 To UBound(vTrg)
vItm = WorksheetFunction.Index(vTrg, lRow, 0)
If vItm(1) = vValue Then sOutput = sOutput & Chr(44) & vItm(2)
Next
sOutput = Replace(sOutput, Chr(44), vbNullString, 1, 1)
Match_Concatenated = sOutput
End Function
Suggest to read the following pages to gain a deeper understanding of the resources used:
Excel functions (alphabetical),
Create an array formula,
Guidelines and examples of array formulas,
Option Explicit Statement,
Range.Value2 Property (Excel), For...Next Statement,
WorksheetFunction Object (Excel), INDEX function,
If...Then...Else Statement, Replace Function
I have a set of names in a column "A" having "Dr.", "Prof." as prefix. I need to remove these prefixes and retain only names.
**Column A** **Required only names in column B**
Prof.Dr.med.nameX
Dr.med.nameXX
Prof. name XXX
Dr. XX
Pr.XX
Say we have a list of names in column A. First we list the unwanted junk in column C and in B1 we enter:
=TRIM(SUBSTITUTE(A1,INDEX($C$1:$C$6,SUMPRODUCT(ROW($C$1:$C$6)*ISNUMBER(SEARCH($C$1:$C$6,A1)))),""))
and copy down:
Derived from Mike H. answer
Maybe this:
=RIGHT(A1,LEN(A1)-FIND(".",A1))
Not tested!
If you have a very short and fixed-length list of substrings that you want to remove, you could do something like:
= TRIM( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( C1, $A$1, "" ), $A$2, "" ), $A$3; "" ), $A$4, "" ), $A$5, "" ) )
(with your original string in C1 and the range of substringsto be removed in A1:A5) .This is a bit messy though and not quite flexible. If you have no objections to using vba, I would propose to write a UDF similar to this:
Function UDF_MultiSubstitute(text As String, old_text_rng As Range, newText As String)
Dim curCell As Range
For Each curCell In old_text_rng
text = Replace(text, curCell.Value, newText)
Next
UDF_MultiSubstitute = Trim(text)
End Function
which you can then invoke as:
= UDF_MultiSubstitute( C1, $A$1:$A$5, "" )
Obviuosly, you might want to add some error trapping etc. to the vba code