User-Defined CODES in VisualBasic Editor – Excel (only)
Functia REMOVENUMBERS(CELL)
Function RemoveNumbers(t As String)
Dim i As Long, newString As String
For i = 1 To Len(t)
If Not IsNumeric(Mid(t, i, 1)) Then
newString = newString & Mid(t, i, 1)
End If
Next i
RemoveNumbers = newString
End Function
To delete leading/trailing spaces =TRIM(RemoveNumbers(cell))
Subrutina Change all cells in a worksheet with values from formulas
Sub All_Cells_In_All_WorkSheets_1()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.Select
With sh.UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
Next sh
End Sub
Sub All_Cells_In_All_WorkSheets_2()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.UsedRange
.Value = .Value
End With
Next sh
End Sub
Subrutina Extract number only from text string
Sub ExtrNumbersFromRange()
Dim xRg As Range
Dim xDRg As Range
Dim xRRg As Range
Dim nCellLength As Integer
Dim xNumber As Integer
Dim strNumber As String
Dim xTitleId As String
Dim xI As Integer
xTitleId = "KutoolsforExcel"
Set xDRg = Application.InputBox("Please select text strings:",
xTitleId, "", Type:=8)
If TypeName(xDRg) = "Nothing" Then Exit Sub
Set xRRg = Application.InputBox("Please select output cell:",
xTitleId, "", Type:=8)
If TypeName(xRRg) = "Nothing" Then Exit Sub
xI = 0
strNumber = ""
For Each xRg In xDRg
xI = xI + 1
nCellLength = Len(xRg)
For xNumber = 1 To nCellLength
If IsNumeric(Mid(xRg, xNumber, 1)) Then
strNumber = strNumber & Mid(xRg, xNumber, 1)
End If
Next xNumber
xRRg.Item(xI) = strNumber
strNumber = ""
Next xRg
End Sub