0% found this document useful (0 votes)
46 views2 pages

Excel (Only) : Functia Removenumbers (Cell)

This document contains code snippets for various functions and macros in Visual Basic for Applications for Excel: 1. The RemoveNumbers function removes all non-numeric characters from a string. 2. A macro to change all cells in a worksheet to values by copying and pasting values. 3. A macro that extracts only the numeric characters from a text string and outputs it to a selected cell.

Uploaded by

ungureanugeorge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Excel (Only) : Functia Removenumbers (Cell)

This document contains code snippets for various functions and macros in Visual Basic for Applications for Excel: 1. The RemoveNumbers function removes all non-numeric characters from a string. 2. A macro to change all cells in a worksheet to values by copying and pasting values. 3. A macro that extracts only the numeric characters from a text string and outputs it to a selected cell.

Uploaded by

ungureanugeorge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like