How to Extract Date from between two underscores in Filename by Formula in Excel? - excel-2016

I need to extract the date from the middle of Excel filenames by formula. Length of text before and after underscores may vary so I am trying to do it based on the underscores. E.g. filenames:
XXX123_20190122_XXXABC
XX123_20190121_XXXABCD
XXXX123_20190120_XXXABC
I can do it in two different formulae:
This gets the filename:
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND(".",CELL("filename",A1))-1-FIND("[",CELL("filename",A1)))
and this takes the date from that cell:
=MID(A9, FIND("", A9, 1)+1, FIND("", A9, FIND("", A9, 1)+1) - FIND("", A9, 1) -1 )
But I need to do it in one forumla and I have not been able to combine them yet. Does anyone know how to do it?
Thank you,

Finally got it, hopefully this will save someone that time and effort. Perhaps there is a more elegant solution but this works if it has to be a formula:
=MID(MID(CELL("filename",$A$1),FIND("[",CELL("filename",$A$1))+1,FIND(".",CELL("filename",$A$1))-1-FIND("[",CELL("filename",$A$1))), FIND("", MID(CELL("filename",$A$1),FIND("[",CELL("filename",$A$1))+1,FIND(".",CELL("filename",$A$1))-1-FIND("[",CELL("filename",$A$1))), 1)+1, FIND("", MID(CELL("filename",$A$1),FIND("[",CELL("filename",$A$1))+1,FIND(".",CELL("filename",$A$1))-1-FIND("[",CELL("filename",$A$1))), FIND("", MID(CELL("filename",$A$1),FIND("[",CELL("filename",$A$1))+1,FIND(".",CELL("filename",$A$1))-1-FIND("[",CELL("filename",$A$1))), 1)+1) - FIND("", MID(CELL("filename",$A$1),FIND("[",CELL("filename",$A$1))+1,FIND(".",CELL("filename",$A$1))-1-FIND("[",CELL("filename",$A$1))), 1) -1 )

Related

Excel VBA: How to convert numbers to ranges

I have some numbers and I want to list their ranges
0O6X6768
0O6X6769
0O6X7468
0O6X7469
0O6X7470
0O6X7477
0O6X7478
0O6X7479
0O6X7482
0O6X9383
Like these, I want to turn them into
0O6X6768 0O6X6769 0O6X7468~0O6X7470 0O6X7477~0O6X7479 0O6X7482 0O6X9383
The first three characters will be the same, but the third to fourth characters will change, so I wrote a judgment
IsNumeric(Right(Cells(i, "A"), 4))
If TRUE then
CInt(Right(Cells(i, "A"), 4))
If Flase then
CInt(Right(Cells(i, "A"), 3))
convert them to numbers and then subtract the next cell from this one to determine if it is 1
But this way
0O6X6768 0O6X6769
will become
0O6X6768~0O6X6769
I think there should be a better solution, how should I do it?
Here are some examples
examples.xlsx download
Thank you all.

Spreadsheet - Conditional formatting cells based on other cells

Conditional formatting a cell is simple enough. It's also simple enough to conditionally format a single cell based on another single cell. What I'm not sure about is doing it for many cells in such a way that I don't have to format each individual cell. For example:
Suppose the cells in column A either have a string, or are blank. How can I set conditional formatting on the cells in column B, such that the formatting is only applied if the A column cell on the same row (ie, the adjacent cell) is blank?
So far, I've been working around this issue by wrapping the formulas of the cells in B with IF(ISBLANK(A1),0,"FORMULA"), then applying conditional formatting to the B cells based on whether the cell values equal 0. Is there a better solution than this?
Yes, in my opinion. For LibreOffice Calc select ColumnB, Format > Conditional Formatting..., choose Formula is and enter:
A1=""
then a style of your choice and OK.
You might want to reduce the upper limit of Cell Range.
Apply the condition to Column B:
And use the following formula:
=NOT(ISBLANK($A1))
This will result in something like this:
=NOT(ISBLANK(OFFSET($A$1, ROW()-1, 0, 1, 1)))

Excel vba - resize as date format

I have a line in code:
.Range("D2").Resize(UBound(vef, 1), 1) = vef
Where vef is an array with data. Can I edit this line so it pastes vef in Date format dd.mm.yyyy hh:mm:ss
That should be easy enough. All you need to do is work with the same range and change the numberformat of the cells. Please note: the value being pasted is unchanged (and the values in your array should be dates). Excel applies a formatting so that what is displayed is changed, but without losing the underlying information.
If your array is full of strings, you will want to look at converting them to Dates beforehand. Excel may do this implicitly (e.g it may automatically format them, despite the original values being dates), but explicit conversion is preferred.
For your code, use this:
With .Range("D2").Resize(UBound(vef, 1), 1)
.Value = vef
.Numberformat = "dd.mm.yyyy hh:mm:ss"
End With
Finally, I would just point out that your Ubound(vef, 1) will only work if your array is 1 based. If it is 0 based, your resized range will be off by 1. The formula you can use to find the length of a dimension in an array is:
Length = (Ubound(Array, DimensionNumber) - LBound(Array, DimensionNumber)) + 1
So in your case:
Length = (Ubound(vef, 1) - LBound(vef, 1)) + 1
Good luck!

Sum numbers that contain a letter in the cell

I'm trying to sum a3:b21 but in these cells they will either have a c or s as the first character in the cell, Some cells might just be the letter itself. the values can be in the range of $1 all the up to $99999.
I have tried a few different formulas but none are adding the cells. Some of the formulas I have tried are
=SUM(IF((LEFT(A3:B20,1))=C3,(--RIGHT((IF(A3:B20="",0,A3:B20)),7)),0))
=IF(ISNUMBER(A3:B20),M3,VALUE(RIGHT(M3,SEARCH(" ",A3:B20)-1)))
=SUMIF(A3:B20,M2,A3:B20)
=SUMIF(A3:B19, "s*")
For the time being while I try and figure out a formula that works I have m2 for the letter s and m3 for the letter c, for testing different formulas.
Sample cell:
If you can add a column and sum from that try this, it acts like a replace() function. Will remove c and s. You can nest other substitutes() to remove other characters as necessary
=substitute(substitute("a3","c",""),"s","")+0
Then copy for other cells
This worked for me.
=SUMPRODUCT(--(LEFT(A1:A3,1)="c"),IFERROR(--RIGHT(A1:A3,LEN(A1:A3)-1),0))
CSE-entered.

Formatting decimal number in excel 2007

I have tables with decimal numbers and i wnat that there will be maximum 2 digits after the point. e.g the number 4.567 will be 4.67, but the number 2 will stay 2, and the number 5.6 will stay 5.6. How can i do that? I managed to do that there will be only two digits, but the number 2 converted to 2.00 and 5.6 to 5.60...
Format Cells->Number->Custom...and enter "0.##"
The "0" means "always displayed" (so in this case a digit before the decimal point). The "#" means "display if present" (so up to two digits after the decimal point). It's not quite perfect as "2" will display as "2.", but I think it's close as you're going to get
To add to #Ed 's answer, if you really want to display whole numbers without the . add a conditional format to the cell using formula (eg for cell A3)
=A3-TRUNC(A3,0)=0
and apply the general format
Related article: Excel 2007 ROUND Function
The syntax for the ROUND function is:
= ROUND ( Number, Num_digits )
1.Enter the following data into cell C1: 34.567
2.Click on cell D1 in the spreadsheet - this is where the function will be located.
3.Type " = round ( " in cell C1.
4.Click on cell D1 in the spreadsheet to enter the data in that cell into the formula.
5.Type a comma ( , ) followed by the number (one (1) or HOW MUCH YOU WANT) in cell D1 to indicate that the data should be reduced to one decimal place.
6.Type the closing bracket " ) " .
7.Press the ENTER key on the keyboard.
8.The answer 34.6 appears in cell D1.
9.If you click on cell D1, the complete function = ROUND ( 34.567 , 1 ) appears in the formula bar above the worksheet.