Formula to determine error code based on binary text output - excel

I am trying to translate some error codes using 22 different formulas and concatenating them afterward to report all errors.
Here is an example of the error code (it is 22 1's and 0's):
0000000000000000001000
0000000000001000000000
0000100000001000000010
Each 1 represents a different error.
Here is one example of the formula I am using:
=IF(NUMBERVALUE(LEFT(D61,1))>=1, " ERROR 1","")
I have 22 of these formulas and the only differences in any of them are the result and which character it looks for.
My issue is a code with multiple different errors (i.e. more than one 1 is present in the code) will show every error code after the first occurrence of a 1. So in the third error code example I listed above, my formula shows every error code after that first 1. Also, it may not matter but I am using this to combine the resulting errors into 1 column:
=CONCATENATE(F2,G2,H2,I2,J2,K2,L2,M2,N2,O2,P2,Q2,R2,S2,T2,U2,V2,W2,X2,Y2,Z2,AA2)
I am trying to get my formula to show just the corresponding errors that go with the 1's, not everything after it. I hope this makes sense as it's kind of hard to explain.
If it helps at all the data is being extracted from text files that come in daily and I had to format the cells as "Text" in order for them to show the 0's before the 1's.
Thanks!
---- EDIT FOR ANYONE CURIOUS ----
This formula ended up working, I placed it in column D, the 22 character code is in column E.
=IF(MID(E2,1,1) > "0","ERROR 1 ","") & IF(MID(E2,2,1) > "0","ERROR 2 ","") & IF(MID(E2,3,1) > "0","ERROR 3 ","") & IF(MID(E2,4,1) > "0","ERROR 4 ","") & IF(MID(E2,5,1) > "0","ERROR 5 ","") & IF(MID(E2,6,1) > "0","ERROR 6 ","") & IF(MID(E2,7,1) > "0","ERROR 7 ","") & IF(MID(E2,7,1) > "0","ERROR 7 ","") & IF(MID(E2,8,1) > "0","ERROR 8 ","") & IF(MID(E2,9,1) > "0","ERROR 9 ","") & IF(MID(E2,10,1) > "0","ERROR 10 ","") & IF(MID(E2,11,1) > "0","ERROR 11 ","") & IF(MID(E2,12,1) > "0","ERROR 12 ","") & IF(MID(E2,13,1) > "0","ERROR 13 ","") & IF(MID(E2,14,1) > "0","ERROR 14 ","") & IF(MID(E2,15,1) > "0","ERROR 15 ","") & IF(MID(E2,16,1) > "0","ERROR 16 ","") & IF(MID(E2,17,1) > "0","ERROR 17 ","") & IF(MID(E2,18,1) > "0","ERROR 18 ","") & IF(MID(E2,19,1) > "0","ERROR 19 ","") & IF(MID(E2,20,1) > "0","ERROR 20 ","") & IF(MID(E2,21,1) > "0","ERROR 21 ","") & IF(MID(E2,22,1) > "0","ERROR 22 ","")

put this in F2 and copy/drag over:
=IF(--MID($D2,column(A:A),1)=1," ERROR " & COLUMN(A:A),"")
If you have Office 365 Excel, you can combine them all into one Array formula that will test each part and return the concatenated values:
=TEXTJOIN(" ",TRUE,IF(--MID($D2,ROW($1:$22),1) = 1, "ERROR " & ROW($1:$22),""))
This one being an array formula needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

With a typical 22 bit value in cell A1, in B1 enter:
=IF(MID($A$1,ROWS($1:1),1)="1","Error # "&ROWS($1:1),"")
and copy down:
To improve the results (remove the ugly empties), in C1 enter the array formula:
=IFERROR(INDEX($B$1:$B$22,SMALL((IF(LEN($B$1:$B$22),ROW(INDIRECT("1:"&ROWS($B$1:$B$22))))),ROW(A1)),1),"")
and copy down:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
EDIT#1:
Put the following User Defined Function UDF() in a standard module:
Public Function ErrorLister(s As String)
Dim arr(1 To 22) As String
Dim i As Long, j As Long
For i = 1 To 22
arr(i) = ""
Next i
j = 1
For i = 1 To 22
If Mid(s, i, 1) = "1" Then
arr(j) = "Error " & i
j = j + 1
End If
Next i
ErrorLister = arr
End Function
Then select B1 through W1, click in the Formula Bar, and enter the array formula:
=ErrorLister(A1)
then copy B1 through W1 downwards:

Related

Why do we use "&cell_reference&" in Excel?

Lets say we have a table like this:
A
B
1
Aaron
20
2
Bob
30
What is the difference between =""&A1&" has "&B1&" cakes" and = A1 & " has " & B1 & " cakes"?
Why do we use "&cell_reference&" anyways?

How to keep the cell reference in VBA

Lets say I have the following data:
A B C
1 =B1
2 =C2
3 =C3
I want to write a macro than can add text around the values in column A without losing the reference.
For example
A B C
1 [Hello].[1] 1
2 [Hello].[20] 20
3 [Hello].[10] 10
As an example for A1 I use:
.cells(1,1) = "[Hello].[" & .cell(1,2) & "]"
This give me the wanted value but in the end I lose the cell reference in A1.
I rather want this:
A B C
1 [Hello].[B1] 1
2 [Hello].[C2] 20
3 [Hello].[C3] 10
Of course with the actual value of the reference and not just the addresses.
With .cells(1,1)
.value = "=" & .cell(1,2).address
.format= ""[Hello].[" 0 "]""
End With
this should do. more info on this excel exotic syntax on that random website https://exceljet.net/custom-number-formats
best of luck, but consider using another language than vba

VLOOKUP, multiple criteria

I have a tab that has 2 cells which list a room number and start time for a class. In this same tab I am performing a VLOOKUP formula.
=VLOOKUP(A12&B3,'Fall 2018 export - TEST'!AF2:AF4,1)
Here A12 is a class room name, and B3 contains the start time.
The array ('Fall 2018 export - TEST'!AF2:AF4,1) for the VLOOKUP comes from a different tab and contains multiple text. Each cell in the array looks like this but with different numbers and start times.
B8007-1, WJW 326,Class Length: 1.30 hrs. Start Time: 9:00 AM
Also, the cell above is a formula:
=IF(AE2<>0,CONCATENATE($C2,"-",$E2,", ",$AE2,",","Class Length: ",TEXT($W2,"h.mm")&" hrs.", " Start Time: ", TEXT($S2,"h:mm AM/PM")),0)
The issue I'm having is, every time I try the VLOOKUP formula, it gives me the wrong data.
For example: using this formula
=VLOOKUP(A12&B3,'Fall 2018 export - TEST'!AF2:AF4,1)
[with A12 & B3 values as 'WJW 100' and '9:00 AM"]
gives me this
"B8007-3, WJW 100, Class Length: 1.30 hrs. Start Time: 12:30 PM"
In other words -- it doesn't give me the cell with the correct start time.
Any help would be appreciated.
Use:
=VLOOKUP("*" & A12 & "*" & TEXT(B3,"h:mm AM/PM") & "*",'Fall 2018 export - TEST'!AF2:AF4,1,False)

to get last row of each day from excel sheet

i need to find the last record of each day in excel if there are multiple entries
*******intention is to get EOD balance ROW OF EACH DATE********
like i have data in excel something like this
date CR_DR amount EOD balance
----------------------
7/9/2017 19:09 CR 10 10
7/10/2017 18:37 CR 25 35
7/10/2017 21:06 DR 10 25
7/11/2017 19:21 CR 15 40
7/15/2017 14:17 DR 20 20
7/17/2017 17:12 CR 100 120
7/18/2017 7:44 DR 30 90
7/18/2017 14:08 DR 50 40
7/18/2017 16:52 CR 120 160
for which i need to get data like (get the last row of each day)
7/9/2017 19:09 CR 10 10
7/10/2017 21:06 DR 10 25
7/11/2017 19:21 CR 15 40
7/15/2017 14:17 DR 20 20
7/17/2017 17:12 CR 100 120
7/18/2017 16:52 CR 120 160
Solution 1
Enter the following formula in Cell F2
=IFERROR(MAX(IF(INT($A$2:$A$10)=INT(INDEX($A$2:$A$10, MATCH(0, FREQUENCY(IF(EXACT(INT($A$2:$A$10), TRANSPOSE(INT($F$1:F1))), MATCH(ROW($A$2:$A$10), ROW($A$2:$A$10)), ""), MATCH(ROW($A$2:$A$10), ROW($A$2:$A$10))), 0))),$A$2:$A$10,0)),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter. Drag/Copy down as required.
Then in Cell G2 enter
=VLOOKUP($F2,$A$2:$D$10,COLUMN(C1)-COLUMN($A$1),FALSE)
Drag this formula across (to right) till Cell I2 and down as required.
See image for reference.
Solution 2
Instead of using an ugly looking long formula, here we'll use a helper column.
In Cell F2 enter the following formula
=MAX(IF(INT($A$2:$A$10)=INT(A2),$A$2:$A$10,0))
This is an array formula so commit it by pressing Ctrl+Shift+Enter. Drag/Copy down as required.
Then in Cell G2 enter
=IFERROR(INDEX($F$2:$F$10,MATCH(0,INDEX(COUNTIF($G$1:G1,$F$2:$F$10),0,0),0)),"")
Drag/Copy down as required.
Finally, in Cell H2 enter
=VLOOKUP($G2,$A$2:$D$10,COLUMN(C1)-COLUMN($A$1),FALSE)
Drag this formula across (to right) till Cell J2 and down as required.
See image for reference.
EDIT : As per comment.
Instead of
=VLOOKUP($G2,$A$2:$D$10,COLUMN(C1)-COLUMN($A$1),FALSE)
use below formula in Cell H2
=INDEX(B$2:B$10,MAX(IF($A$2:$A$10=$G2,ROW($A$2:$A$10)-ROW(INDEX($A$2:$A$10,1,1))+1)))
This is an array formula so commit it by pressing Ctrl+Shift+Enter. Drag this formula across (to right) till Cell J2 and down as required. Drag/Copy down as required.
Screen-Shot :
Ok, this is crude and I'm sure there are "proper" ways to do this, but it works for what you want to do. I used columns A thru D for the data. In column F I used the formula =Left(A3,5) and copied it down. You will have to modify according to your situation. Hope this helps or gets you headed in right direction. Good Luck
Sub FindLast()
'FIND LAST LISTED DATE AND COPY
Dim myCount, myCount2, myRange, myRow, x, y, r
r = 3
myCount = Sheets("Sheet1").UsedRange.Rows.Count - 2
MsgBox "Rows used are " & myCount
For x = 3 To myCount Step 1
y = Range("F" & x).Value
MsgBox "Value of x is " & x
MsgBox "Value of y is " & y
myCount2 = WorksheetFunction.CountIf(Range("F3:F" & myCount + 2), y)
MsgBox "myCount2 value is " & myCount2
Max_date = Application.WorksheetFunction.Max(Range("A" & x & ":" & "A" & x + myCount2 - 1))
myRow = Range("A" & x + myCount2 - 1).Row
MsgBox "myRow number is: " & myRow
MsgBox CDate(Max_date)
Sheets("Sheet1").Range("I" & r).Value = Max_date
Sheets("Sheet1").Range("J" & r).Value = Range("B" & myRow).Value
Sheets("Sheet1").Range("K" & r).Value = Range("C" & myRow).Value
Sheets("Sheet1").Range("L" & r).Value = Range("D" & myRow).Value
r = r + 1
If myCount2 <> 1 Then
x = x + (myCount2 - 1)
Else
x = x
End If
Next x
End Sub
You will notice there are a lot of message boxes. I used these to test the parameters and make sure they were coming out like I wanted. When you are comfortable with how it's working, just comment them out.
Also, the output is set to I3 thru L8 for the example you posted. Please make sure to edit these if your real sheet has any data in these areas. My suggestion is test first to get familiar with what's happening. I did't put any "failsafes" or "exits" in, as I ran out of time. There are plenty of examples on this site to help with that.
Regards
It requires entering the dates in column A (I didn't feel motivated enough to figure out how to pull the unique ones out), but if you are feeling spunky, you could use some array formulas. :-)
Column A Column B C D E
7/9/2017 7/9/2017 19:09 CR 10 10
7/10/2017 7/10/2017 21:06 DR 10 25
7/11/2017 7/11/2017 19:21 CR 15 40
7/15/2017 7/15/2017 14:17 DR 20 20
7/17/2017 7/17/2017 17:12 CR 100 120
7/18/2017 7/18/2017 16:52 CR 120 160
Enter dates in column A. Then in column B enter:
=IFERROR(INDEX(Date,SMALL(IF(ROUNDDOWN(Date,0)=$A1,ROW(Date)-1),COUNTIFS(Date,">="&$A1,Date,"<"&$A1+1))),"")
closing out of the cell with CTRL-SHIFT-ENTER so that the formula in the formula bar looks like
{=IFERROR(INDEX(Date,SMALL(IF(ROUNDDOWN(Date,0)=$A1,ROW(Date)-1),COUNTIFS(Date,">="&$A1,Date,"<"&$A1+1))),"")}
Note: it does not work to enter the curly braces yourself. ;-) You must close out of the cell with CTRL-SHIFT-ENTER!
The Date in the formula is a named range - I don't like typing $A$2:$A$10 all the time. If you don't want to do named ranges, replace Date with $A$2:$A$10 or your applicable range.
Column C:
=IFERROR(INDEX(CR_DR,SMALL(IF(ROUNDDOWN(Date,0)=$A1,ROW(Date)-1),COUNTIFS(Date,">="&$A1,Date,"<"&$A1+1))),"")
Same thing - close out of cell with CTRL-SHIFT-ENTER. Named range again for CR_DR, same rules as for Date above. Copy/paste the for the other columns, changing the range that INDEX is searching as appropriate for the column you want.
Explanation: ROUNDDOWN removes the time from the date in your source data so that it can match it to the date in column A. If the date matches, its row (-1 because the row number of A2 is 2, but it is the first item in $A$2:$a$10) is put into an array for the SMALL function. This chooses the nth smallest item from the array, defined by the COUNTIFS function, which counts how many dates fall between the date in column A and the day after the date in column A (thus actually giving you the largest item). INDEX then uses the range and looks up the row number that SMALL delivered to it. If it errors out, the cell is blank.
If you don't want to hand-enter specific dates, auto-fill for all dates and it will simply be blank on dates with nothing:
7/9/2017 7/9/2017 19:09 CR 10 10
7/10/2017 7/10/2017 21:06 DR 10 25
7/11/2017 7/11/2017 19:21 CR 15 40
7/12/2017
7/13/2017
7/14/2017
7/15/2017 7/15/2017 14:17 DR 20 20
7/16/2017
7/17/2017 7/17/2017 17:12 CR 100 120
7/18/2017 7/18/2017 16:52 CR 120 160

How to find out empty cell reference?

I have the following table:
Roll No Eng Hin Mar Math
1 10 10 10
2 10 10
3 10 10
4 10 10
5 10 10
6 10 10 10
7 10 10 10
8 10 10 10
I need to find out only blank cells and highlight only those students who are left blank. For example, Roll no 1 is blank at Hin column and Roll no 2 is blank at Eng and Math:
Roll No Pending Sub
1 Hin
2 Eng & Math
Can anyone tell me how to get that result?
I have changed the layout of the data in your OP to try to match it to your example and am interpreting "highlight" as more "draw attention to" than any particular formatting.
Assuming Roll No is in A1, please try in say G2 and copied down to suit:
=LEFT(IF(ISBLANK(B2),B$1&" & ","")&IF(ISBLANK(C2),C$1&" & ","")&IF(ISBLANK(D2),D$1&" & ","")&IF(ISBLANK(E2),E$1&" & ",""),LEN(IF(ISBLANK(B2),B$1&" & ","")&IF(ISBLANK(C2),C$1&" & ","")&IF(ISBLANK(D2),D$1&" & ","")&IF(ISBLANK(E2),E$1&" & ",""))-3)

Resources