Input in column H from Row 2
column H
90 million +
550 million +
150 million +
2.1 billion +
110 million +
.
.
.
Expected Output in Column J from Row 2
90
550
150
2.1
110
.
.
.
VBA Code:
Option Explicit
Sub ConvertRange()
Dim str As String
Dim Cet
Dim i, j, l As Long
Dim FinalRow As Long
Dim wk As Worksheet
Application.ScreenUpdating = False
Set wk = Sheets("Sheet1")
FinalRow = wk.Range("H900000").End(xlUp).Row
For i = 2 To FinalRow
str = Cells(i, "H").Value
str = Replace(str, " ", "+")
str = Replace(str, "", "+")
str = Replace(str, " ", "+")
Cet = Split(str, "+")
Range("J" & i) = Cet(LBound(Cet))
Next i
Application.ScreenUpdating = True
End Sub
But I am getting wrong Output in Column J As follows
90 million
550 million
150 million
2.1 billion
110 million
.
.
.
I believe either of these commands would have replaced the white spaces with the + sign
str = Replace(str, "", "+")
str = Replace(str, " ", "+")
And following line would have an Array wherein LBound value id Cet should be only numbers
Cet = Split(str, "+")
Where am I wrong ?
Basically what I want is Cet(0) should be the long or integer number and Cet(1) should be the text billion or million depending on the text in col H for every loop so that I can process this further
So if Column H Row 2 value is 90 million Cet(0)=90 and Cet(1)=million
Range("J" & i) = split(str, " ")(0). Without all theReplacestr = Replace(str, "", "+")is not replacing white space. It's replacing nothing. In other words, a replacement isn't happening at all where you think it is. I would add that you probably don't need VBA for this; a simple formula would suffice.2.1is the largest number here...