mardi 29 mai 2018

Formatting Cells with Numeric values as Numbers

a very trivial question for you illuminated lot. I am basically trying to identify each cell in a range which has a numeric value, and then format it as 'number' (hence overlooking those cells which contain a string). I have found an excel formula which uses an IF and TRUE/FALSE expression to figure out which cell match the condition, but when running the code in VBA I cannot seem to store the IF statement?

It is probably very silly, as I am new to VBA, but would appreciate all the help!

Code below:

Sub formatnumbers()

Dim rng As Range
Dim cell As Range

Set rng = ActiveSheet.Range("A1:N10")

For Each cell In rng
 cell.Select
         If cell.Formula = "=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},cell))>0, TRUE, FALSE)" = True Then
            cell.NumberFormat = "0.00"
         End If

Next cell

End Sub

Aucun commentaire:

Enregistrer un commentaire