Determine cells with "General" number format

P

PBcorn

I need a VB expression so I can test for cells with a "general" format as
opposed to "number" format. Is there a property statement which will do this?

Thanks
 
P

Peter T

Sub Test()
Dim vGen As Variant
Dim cel As Range
Dim rng As Range

Set rng = Range("A1:A10")

vGen = rng.NumberFormat = "General"

If IsNull(vGen) Then
MsgBox "at least one cell is General but not all"
For Each cel In rng
Debug.Print cel.Address, cel.NumberFormat
Next
ElseIf vGen = True Then
MsgBox "all cells are General"
Else
MsgBox "no cells are General"
End If

End Sub

Regards,
Peter T
 
J

Jacob Skaria

If Range("A1").NumberFormat = "General" Then
'do something
End If

If this post helps click Yes
 
G

Gijs

Sub Test()
Dim vGen As Variant
Dim cel As Range
Dim rng As Range

    Set rng = Range("A1:A10")

    vGen = rng.NumberFormat = "General"

    If IsNull(vGen) Then
        MsgBox "at least one cell is General but not all"
        For Each cel In rng
            Debug.Print cel.Address, cel.NumberFormat
        Next
    ElseIf vGen = True Then
        MsgBox "all cells are General"
    Else
        MsgBox "no cells are General"
    End If

End Sub

Regards,
Peter T







- Show quoted text -

Hi,
I am able to test on the General format.
My problem is that the value property is always null in case of the
general format.
Value contains the right value for numeric and text format.
Where do I find the cell value in case of 'General'?
Who can help me?
Thanks,
Gijs
 
P

Peter T

I don't follow what you are saying, there is no direct connection between
cell's Value and Numberformat properties

When testing a particular format in a multi-cell range, if they are not all
the same the returned value will be Null (which can only be assigned to a
Variant)

What are you trying to do

Regards,
Peter T
 
K

keiji kounoike

Do you mean you want to find cells that have a General format and that
cells's value is a number or a text to be considered as number?

Keiji
 

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