VBA or Macro solution to convert Percentages to decimals

Z

Zuzeppeddu

Hi all

I have a few hundred excel files which have percentage data in them. I
want to replace that percentage data into a decimal value rounded to
two decimal points.

For example:

15.345000021 (which appears as 15% in the cell) to 15.35

What I would like to do is to open each excel file, highlight all the
cells with percentage values, and apply a macro which will do this
transformation, instead of doing it manually column by column.

I would be very grateful if anyone could guide me to do this.

Thanks
Yousaf
 
J

JE McGimpsey

One way:

Public Sub PercentsToDecimal()
Dim rCell As Range
For Each rCell In ActiveSheet.UsedRange.Cells
With rCell
If .NumberFormat Like "*%*" Then
.Value = Application.Round(.Value * 100, 2)
.NumberFormat = "0.00"
End If
End With
Next rCell
End Sub
 
Z

Zuzeppeddu

Thanks so much. It works!

One way:

Public Sub PercentsToDecimal()
Dim rCell As Range
For Each rCell In ActiveSheet.UsedRange.Cells
With rCell
If .NumberFormat Like "*%*" Then
.Value = Application.Round(.Value * 100, 2)
.NumberFormat = "0.00"
End If
End With
Next rCell
End Sub









- Show quoted text -
 

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