Converting non-uniform Excel data into uniform data by VBA

Yup

New Member
Joined
Sep 6, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi, I had a question.
I wanted to convert non-uniform data in single Excel column to uniform data into another column.
Example- I have an Excel column containing values as 345.12 million, 128.56 billion, 2.67 trillion and I would like to convert this non-uniform data into a uniform way using VBA i.e. the expected outcome should either be

0.34512 billion, 128.56 billion, 2670 billion

OR

345120000, 128560000000, 2670000000000.

Is there any way it is possible ?

Thank you in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi
What about
VBA Code:
Sub test()
    Dim a, x, y
    Dim i&
    Dim m As Object
    a = Range(Cells(2, 1), Cells(2, 1).End(xlDown))
    x = Application.Index(Array("million", "billion", "trillion"), 0, 0)
    y = Application.Index(Array("1000000", "1000000000", "1000000000000"), 0, 0)
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[\d+\.*]+|[a-zA-Z]+"
        For i = 1 To UBound(a)
            Set m = .Execute(a(i, 1))
            a(i, 1) = m(0) * y(Application.Match(m(1), x, 0))
        Next
    End With
    Cells(2, 2).Resize(UBound(a)) = a
End Sub
 
  • Like
Reactions: Yup
Upvote 0
Welcome to the MrExcel board!

If the only options are million, billion and trillion, try this

VBA Code:
Sub Convert_Numbers()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .NumberFormat = "0"
    .Value = Evaluate(Replace("left(#,FIND("" "",#))*if(right(#,7)=""million"",10^6,if(right(#,7)=""billion"",10^9,10^12))", "#", .Offset(, -1).Address))
  End With
End Sub

My sample data (col A) and results (col B)

Yup.xlsm
AB
1
2345.12 million345120000
3128.56 billion128560000000
42.67 trillion 2670000000000
Sheet3
 
  • Like
Reactions: Yup
Upvote 0
Solution

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

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