need only data

sksanjeev786

Well-known Member
Joined
Aug 5, 2020
Messages
884
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Team,

I have data in various formate. can I get any formula to find only data. There will be % space on random data but I need only data i.e 32 data can be in single digit as well. (instead of 32 it can be 8 with all below condtion)

32%A, (%)
32%ab,
32AB, (No Space )
32 AB(only has Space)

Thanks in Advance.
Regards,
Sanjeev
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi
Try This VBA Code in a module
Data start from A2 down
VBA Code:
Sub Test()
    Dim lr, i
    Dim Rg, m As Object
    With ActiveSheet
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
        For i = 1 To lr
            If Rg.Test(Cells(i, 1)) Then
                Set m = Rg.Execute(Cells(i, 1))
                Cells(i, 1).Offset(, 1) = m(0)
            End If
        Next
    End With
End Sub

Hi Mohdin,

Thank you for the VB and I have tried with your macro
and for 23% I am getting a 0 score and rest data I am getting in-text formate as I need in value formate.

thank you :)
Regards,
Sanjeev
 
Upvote 0
Try this to get values
about the 23 I don't understand
Can you post wher you get the 0
VBA Code:
Sub Test()
    Dim lr, i
    Dim Rg, m As Object
    With ActiveSheet
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
        For i = 1 To lr
            If Rg.Test(Cells(i, 1)) Then
                Set m = Rg.Execute(Cells(i, 1))
                Cells(i, 1).Offset(, 1) = m(0)*1
            End If
        Next
    End With
End Sub
 
Upvote 0
Try this to get values
about the 23 I don't understand
Can you post wher you get the 0
VBA Code:
Sub Test()
    Dim lr, i
    Dim Rg, m As Object
    With ActiveSheet
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
        For i = 1 To lr
            If Rg.Test(Cells(i, 1)) Then
                Set m = Rg.Execute(Cells(i, 1))
                Cells(i, 1).Offset(, 1) = m(0)*1
            End If
        Next
    End With
End Sub

now it look great Mohadin. just wanted to check can we give any function in macro as my source is always not in A2 column it can be in any column
so can I give any function so that I can take data from any source.


Thank you.
Sanjeev
 
Upvote 0
Here you go
VBA Code:
Function GDATA(r As Range)
    Dim Rg As Object
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
            If Rg.Test(r) Then
                GDATA = Rg.Execute(r)(0) * 1
            End If
End Function


=GDATA(B2)
 
Upvote 0
Here you go
VBA Code:
Function GDATA(r As Range)
    Dim Rg As Object
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
            If Rg.Test(r) Then
                GDATA = Rg.Execute(r)(0) * 1
            End If
End Function


=GDATA(B2)
it work but for 32% i am getting 0
 
Upvote 0
VBA Code:
Sub Test2()
    Dim lr, i
    Dim Rg, m As Object
    With ActiveSheet
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
        For i = 1 To lr
            If Rg.Test(Cells(i, 1).Value) Then
                Set m = Rg.Execute(Trim(Cells(i, 1)))
                If m.Count = 1 Then
                    Cells(i, 1).Offset(, 1) = m(0) * 1
                Else
                    Cells(i, 1).Offset(, 1) = m(1) * 1
                End If: End If
        Next
    End With
End Sub
 
Upvote 0
VBA Code:
Sub Test2()
    Dim lr, i
    Dim Rg, m As Object
    With ActiveSheet
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
        For i = 1 To lr
            If Rg.Test(Cells(i, 1).Value) Then
                Set m = Rg.Execute(Trim(Cells(i, 1)))
                If m.Count = 1 Then
                    Cells(i, 1).Offset(, 1) = m(0) * 1
                Else
                    Cells(i, 1).Offset(, 1) = m(1) * 1
                End If: End If
        Next
    End With
End Sub

look great !!! Thanks Mohadin for your help:):)
I will add the above code with the previous code you have provided macro in GData

Regards,
sanjeev
 
Upvote 0
VBA Code:
Function GDATA(r As Range)
    Dim Rg, m As Object
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
            If Rg.Test(r) Then
                Set m = Rg.Execute(r)
                If m.Count = 1 Then
                    GDATA = m(0) * 1
                Else
                    GDATA = m(1) * 1
                End If: End If
End Function
 
Upvote 0
Code:
Function GDATA(r As Range)
    Dim Rg, m As Object
        Set Rg = CreateObject("VBScript.RegExp")
        Rg.Global = True
        Rg.Pattern = "\d+"
            If Rg.Test(r) Then
                Set m = Rg.Execute(r)
                If m.Count = 1 Then
                    GDATA = m(0) * 1
                Else
                    GDATA = m(1) * 1
                End If: End If
End Function
 
Upvote 0

Forum statistics

Threads
1,215,942
Messages
6,127,807
Members
449,408
Latest member
Bharathi V

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top