Is cell content text or numeric-need help with existing code

D

dan

This will probably be an easy one for someone. I have the following code:

Dim rng1 as Range
Sub test()
Set rng1 = Range("A1")
If rng1 = 1 Then
rng1.Font.Bold = True
Else:
End If
End Sub

So if the content of cell A1 is the number 1, the code will bold the number.

I want to generalize the "if" statement so that if the content of cell A1 is
numeric, (any minus number, 0, or any positive number) the "if" statement
will bold it, but if there is text in the cell, it will not bold it. How do
I change the code to make that happen?
 
B

Bob Phillips

No probs.

Sub test()
Dim rng1 As Range
Set rng1 = Range("A1")
If IsNumeric(rng1) Then
rng1.Font.Bold = True
Else:
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

dan

Hey Bob - Thanks for your prompt response. It's just what I needed and much
appreciated!

Dan C.
 

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