finding last character on if condition excel - excel

Can you tell me if I want to find the last character in Excel based on condition
let say last character if it is A then replace it with X, or if it is b then replace it with Z.
I want to do it with formula

If your value is in A1 cell, then try applying the following formula in B1 cell.
Formula
=IF(RIGHT(A1,1)="a", LEFT(A1,LEN(A1)-1) &"x", IF(RIGHT(A1,1)="b",LEFT(A1,LEN(A1)-1) & "z",A1))
If you are looking for last character to be exactly A, then try the following formula.
Formula
=IF(EXACT(RIGHT(A1,1),"A"), LEFT(A1,LEN(A1)-1) &"X", IF(EXACT(RIGHT(A1,1),"B"),LEFT(A1,LEN(A1)-1) & "Z",A1))

You can use this formula. See the example sheet to understand the values.
In Example:
"A2": Original Text
"B2": Result
=IF(RIGHT(A2,1)="A",REPLACE(A2,LEN(A2),1,"X"),IF(RIGHT(A2,1)="B",REPLACE(A2,LEN(A2),1,"Z"),A2))

Related

Need excel formula for the below question

Create a formula that returns only the characters that appear after "X" for the given character strings. The same formula must work for the whole column!
Example of how it should look like after you apply your formula:
765892X329 329
752238X44 44
Here’s one that works:
=REPLACE(A1, 1, SEARCH("X", A1), "")
It first finds where the X is in the cell and replaces all the text from the beginning up to where X is with nothing, in other words removing it, leaving you with just the text after X.
Replace both the A1 in the above formula with the cell position you want to apply the formula to.

Conditional LEFT Excel formula (or VBA?) based on formula results?

I have in Column C2, formula results which I need to perform LEFT on in order to trim the cell formula value
The formula result MUST have one of the following (. OR _ OR -) in answer
If one of the above exists in the cell , then LEFT(C2,FIND("the_variable_in_the_formula_answer),C2)-1)
My VBA isn't the best, but I think I could use
variable = Left(Sheet1.[C2],InStr(Sheet1.[C2],".")-1)
I don't know how to make the .(period) , _(underscore) OR -(hyphen) a variable to look for
Try this formula at row two and fill down the column:
=IFERROR(LEFT(Sheet1!C2, AGGREGATE(15,6,SEARCH({".","-","_"},Sheet1!C2),1)-1), "")
It truncates until the first found of {".","-","_"}. If you want to truncate till the last found, change 15 into 14.
For your additional requirements:
=IF(ISNA(C2), D2,
IFERROR(LEFT(Sheet1!C2,AGGREGATE(15,6,SEARCH({".","-","_"},Sheet1!C2),1)-1),C2))

How to add white spaces in a field of Excel which is equal to length of a longer word

I have a scenario where I want my Microsoft excel field to have the same length of the longest word in the column.
Basically lets say if I have:
ACBBASDBBADSAD
BADFDFDDF
So here I want to have the second word with less characters to have white spaces at its end to match the length of the first word.
=&" " this definitely helps but I am unable to achieve the above scenario
Consider this screenshot:
In column B the length of each cell of column A is established with the formula =len(A1) copied down.
Cell D2 has the range name MaximumLength and the formula =max(B:B).
With that in place, you can create the padded values with this formula in cell G1, copied down:
=A1&REPT("*",MaximumLength-LEN(A1))
If you don't want to use the helper column and helper cell, you can use this array formula instead:
=A2&REPT("*",MAX(LEN(A1:A15))-LEN(A2))
This formula must be confirmed with Ctrl-Shift-Enter. It is advisable to use defined ranges, not whole columns in array formulas, hence the range in LEN(A1:A15). Adjust as desired.
I've used the "*" character so it is visible. Replace it with a space " " in your scenario.
You can add this formula to count maximum characters and use on some cell, because you will need to press a command for it to work, so every cell can't contain this formula, let's say it is on Z1:
=MAX(LEN($A:$A))
Certify to press ctrl+shift+enter on the formula
Then you use this formula on your cells:=REPT(" ";Z1-LEN(A2))&A2
Edit: Sorry, anwsered late, teylyn is more complete.

Nested IFs in function not working

Hi, I'm trying to input a function in C2 in order to assign a numerical value to the minutes given in Column B. The criteria for this can be seen in the image above (starting at G1).
I have tried using a formula I copied from a similar situation but is not working:
=IF(B2<=$A$2,5,IF(B2<=$A$3,4,IF(B2<=$A$4,3,IF(B2<=$A$5,2,1))))
Any help would be appreciated, thanks
The suggestion by #Jeeped above will simplify the formulas needed. If you have to keep the 'A' and 'B' cells as they are listed above, you have to extract the number from the 'x min' format and convert the 'x' to a number so it can be compared (I assume a " " exists after the number. Could search for " min" as well).
=VALUE(LEFT(A2,SEARCH(" ",A2)-1))
Using the above, if A2 = '60 min', the formula will produce a '60'.
Now that the cell contents can be treated as numbers, the comparisons can be made. Formula for C2:
=IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$2,SEARCH(" ",$A$2)-1)),5,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$3,SEARCH(" ",$A$3)-1)),4,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$4,SEARCH(" ",$A$4)-1)),3,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$5,SEARCH(" ",$A$5)-1)),2,1))))
This is ugly, but works given the original question.
Try this formula (in this case for C2):
=SUM((B2<=$A$2:$A$5)*1)+1
It is important to use it as array formula. So after typing or inserting this formula to your cell don't just commit with Return but hit Ctrl+Shift+Return. If you did it right, your formula will be surrounded by curly brackets in formula bar:
{=SUM((B2<=$A$2:$A$5)*1)+1}

Excel INDEX and MATCH Get Value

I have an excel workbook that I need some help with INDEX and MATCH or any other Formula that can get me my end result.
Here is sheet1:
SIT_ID METER SUSE_CD
10834282 DT0061 B
10834282 AW7931 P
21676286 CQ9635 P
21676286 DP4838 B
21726281 AW7880 P
21726281 DT0032 B
Here is Sheet2:
Site ID B P
10834282
21676286
21726281
Ultimately what I am trying to do is on Sheet2 is put the Meter that = B for the SITEID in the column and then Put the Meter that = P in the Same row.
I have never used Index or Match and I looked it up online but I am confused and hoping someone can help me with the correct formula or point me in the right direction.
Thanks so much!
INDEX first takes a range, then a row number, an optional column number (and an optional area number).
MATCH takes a value to lookup, an array and a mode.
In your problem you can use the following in Sheet2 cell B2:
=INDEX(Sheet1!$B$2:$B$7, MATCH($A2, IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7), 0))
This formula is an array formula and will work with Ctrl+Shift+Enter and then you can fill it to the other cells.
I had to use an IF because there're two conditions to check.
EDIT: Use this one if your cell formats are different:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7*1),0))
EDIT2: Adding trimming:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(TRIM(Sheet1!$C$2:$C$7)=TRIM(B$1),Sheet1!$A$2:$A$7*1),0))
EDIT3: If you're using it on your full data, change the range:
=INDEX(Sheet1!$B:$B,MATCH($A2*1,IF(TRIM(Sheet1!$C:$C)=TRIM(B$1),Sheet1!$A:$A*1),0))
Assuming your Sheet1 looks like this:
And your Sheet2 looks like this:
The formula in Sheet2 cell B2 and copied over and down to cell C4 is:
=INDEX(Sheet1!$B$2:$B$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$C$2:$C$7=B$1),),0))
Note that this is a regular formula, so no need for Ctrl+Shift+Enter
A helper column D is added to initial columns.
D2: =$A2 & $C2
Now it's possible to make a simple search of the concatenated SITE_ID and SUSE_CD:
H2: =MATCH($G2&" B";$D$2:$D$8;0)
The result would be a row number (=1 in this case) for the needed string in array $D$2:$D$8.
INDEX shows the value of the cell, found by counting n-th row (defined by MATCH) and m-th column (=2) in array $A2:$A$8 from the upper left cell (A2).
Altogether: =INDEX($A$2:$B$8;MATCH($G2&" B";$D$2:$D$8;0);2)
The easiest way to get around with this is,
to use concatenation operator in the match function.
Don't forget to use Ctrl+Shift+Enter
Use below formula in column B of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$B$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And the below formula in column C of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$C$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And then flash fill the remaining rows.

Resources