Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba converting text numbers

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA converting text to numbers

VBA converting text to numbers

ResolvedVersion 2007

Jack has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Excel VBA Advanced course

VBA converting text to numbers

Hi there,

I want to convert a column of numbers stored as text to numbers, i tried using the macro recorder but the coding wasnt picked up.

I tried the following codes but didn't have much luck:

For Each Cell In Selection
Cell.Value = CDec(xCell.Value)

Next Cell

Any help is appreciated!

Thanks
Jack

RE: VBA converting text to numbers

Hi jack

Thanks fopr your question

The following code seems to do the trick

Dim i As Integer

For i = 1 To Range("a1").CurrentRegion.Rows.Count

Cells(i, 5).Value = CDec(Cells(i, 1).Value)


Next i


hope this helps

Regards

Stephen

RE: VBA converting text to numbers

Hi Stephen,

thanks for the email.

I have modified the codes slighty to stop the process at 2nd last row:

Dim i As Integer

Sheets("sheet4").Activate

For i = 1 To Range("A1").End(xlDown).Offset(-1, 0)

Cells(i, 2).Value = CDec(Cells(i, 1).Value)

Next i

This code runs fine and the numbers are copied to column 2 but i get a run time error 13 - type mismatch and the following line is highlighted.

Cells(i, 2).Value = CDec(Cells(i, 1).Value)

everything looks fine and not sure why this is highlighted, the reason i want it to stop at 2nd row from last is because last row is text.

thanks
jack

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

LARGE and SMALL functions and their uses

Two of Excel's most common functions are the MAX and MIN functions which will display the largest (MAX) or smallest (MIN) value in a series. What if you need the 2nd or 3rd largest or smallest values instead of the largest or smallest?

The =LARGE(array,n) returns the nth largest value of a series.

The =SMALL(array,n) function returns the nth smallest value of a series.

In both functions, 'n' represents the order of the number you want to display. For example, putting in 2 as n will give you the second highest number; putting in 3 as n will give you the third highest number.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.