Changing a text field to a number

  • Thread starter Michel Khennafi
  • Start date
M

Michel Khennafi

Hello there!

I imported a MS Project file in excel and I have values in cell like 3.5d (3
and a half days)...I would like to browse all cells and remove the day to
get only the numbers...
The 'd' is always the last character in the cell... I tried using a macro
but failed...

Has anyone any idea about how to browse a column (top to bottom), remove all
the "d" and go to the next column on top

Thank you so muchfor your precious help

Michel
 
R

Ron Rosenfeld

Hello there!

I imported a MS Project file in excel and I have values in cell like 3.5d (3
and a half days)...I would like to browse all cells and remove the day to
get only the numbers...
The 'd' is always the last character in the cell... I tried using a macro
but failed...

Has anyone any idea about how to browse a column (top to bottom), remove all
the "d" and go to the next column on top

Thank you so muchfor your precious help

Michel

Try this macro. First select the area on your worksheet that contains the data
in the format you wish to change. The macro tests that each cell ends in a 'd'
and that the remainder of the cell is a number. If so, it strips of the d and
converts the remainder to a number.

=============
Sub RemoveD()
Dim c As Range

For Each c In Selection
If Right(c.Text, 1) = "d" Or Right(c.Text, 1) = "D" Then
If IsNumeric(Left(c.Text, Len(c.Text) - 1)) Then
c.Value = CDbl(Left(c.Text, Len(c.Text) - 1))
End If
End If
Next c
End Sub
============

--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top