PDA

View Full Version : [SOLVED:] Convert to a number



kmlartigue
08-16-2017, 02:21 PM
I have some values in column A1, when I highlight it, the yellow alert popup appears and on the drop down I click convert to number. What is a good code I can use to tell it the values to convert to a number?

YasserKhalil
08-17-2017, 12:37 AM
Hello
Try this code


Sub Convert_To_Numbers()
Dim rng As Range


On Error Resume Next
Set rng = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(xlCellTypeConstants, 23)
On Error GoTo ErrHandler


If Not rng Is Nothing Then
Cells.SpecialCells(xlCellTypeLastCell).Offset(0, 1).Copy
rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationAdd
Else
MsgBox "Could Not Find Constants In Range", 64
End If


ExitHandler:
Application.CutCopyMode = False
Set rng = Nothing
Exit Sub
ErrHandler:
MsgBox "Could Not Change Text To Numbers", 64
Resume ExitHandler
End Sub

snb
08-17-2017, 01:04 AM
Sub M_snb()
[A1].numberformat="general"
[A1].value=[A1].value
End sub

kmlartigue
08-17-2017, 09:15 AM
For convert to a number I ended up using this code and it works.


Sub CPacctnumvalues()
Range("A3:A1000").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("A3"), DataType:=xlFixedWidth, _
FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1").Select

End Sub