Determine cells with "General" number format

  • Thread starter Thread starter PBcorn
  • Start date Start date
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
 
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
 
If Range("A1").NumberFormat = "General" Then
'do something
End If

If this post helps click Yes
 
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
 
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
 
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
 
Back
Top