Use Excel to extract digital text

Goals: extraction column A in a cell into a target location year

Here Insert Picture Description

My method is to extract numbers, and then insert the symbol transition year "-."

Extract the digital

提取A2单元格数字function:
=SUMPRODUCT(MID(0&A2, LARGE(INDEX(ISNUMBER(–MID(A2, ROW(INDIRECT(“1:”&LEN(A2))), 1)) * ROW(INDIRECT(“1:”&LEN(A2))), 0), ROW(INDIRECT(“1:”&LEN(A2))))+1, 1) * 10^ROW(INDIRECT(“1:”&LEN(A2)))/10)

Digital extraction resultsDigital extraction success

For any selected treatment area caret

使用VBA 插入符号,代码如下:
Sub AddString()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = “KutoolsforExcel”
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox(“Range”, xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = VBA.Left(Rng.Value, 4) & “-” & VBA.Right(Rng.Value, 4)
Next
End Sub

Run the code, select the target area
Run, type selected area

The final processing results
Here Insert Picture Description

Finally, Excel white wonder if there is more concise than this method, but I think that the solution to my needs. Before you follow someone else's online methods found no way to get to so many digits, and pulls out the code to find the formula. Because this is my second successful macro, then could not help but issued to commemorate it.

Reference
Extendoffice. n.d. How To Add Text In Middle Of Selected Cells In Excel https://www.extendoffice.com/documents/excel/2737-excel-add-text-in-middle-of-cell.html#a2

Svetlana Cheusheva. 2019.How to extract number from string in Excel https://www.ablebits.com/office-addins-blog/2017/11/22/excel-extract-number-from-string/

Published an original article · won praise 0 · Views 9

Guess you like

Origin blog.csdn.net/Ice_voice/article/details/104364400