if statement that tests format of cell

  • Thread starter Thread starter medcmatt
  • Start date Start date
M

medcmatt

I am trying to create an if statement that tests the format of the
cell in addition to the value in the cell; specifically I want to test
if the format of the text in the cell is superscript or not. I have
been trying everything I know and this is what I have so far:

ElseIf Trim(ActiveCell.Value) = "2" And
Cells(ActiveCell.Value).FontStyle.Superscript = True Then
sData = "0"

Any help you could provide would be very much appreciated.

Matt
 
Public Function TestFont(cellAddress As Range) As Boolean

If cellAddress.Font.Superscript = True Then
TestFont = True
Else
TestFont = False
End If

End Function
 
I used this and it seems to work:


If ActiveCell.Value = 2 And ActiveCell.Font.Superscript = True Then
MsgBox "boo"
Else
MsgBox "not boo"
End If


I think the problem that you were hitting has to do with your referencing in
the cells()...
cells(activecell.value) , in that case, would pick up the 2 cell in the
index... the value of your active cell was 2, so activecell.value would then
be 2, so essentially, your code says cells(2).fontstyle.superscript
 
I am trying to create an if statement that tests the format of the
cell in addition to the value in the cell; specifically I want to test
if the format of the text in the cell is superscript or not. I have
been trying everything I know and this is what I have so far:

ElseIf Trim(ActiveCell.Value) = "2" And
Cells(ActiveCell.Value).FontStyle.Superscript = True Then
sData = "0"

Any help you could provide would be very much appreciated.

Matt



For Each c In Selection
Debug.Print c.Address, c.Font.Superscript
Next c
--ron
 
I used this and it seems to work:

If ActiveCell.Value = 2 And ActiveCell.Font.Superscript = True Then
MsgBox "boo"
Else
MsgBox "not boo"
End If

I think the problem that you were hitting has to do with your referencing in
the cells()...
cells(activecell.value) , in that case, would pick up the 2 cell in the
index... the value of your active cell was 2, so activecell.value would then
be 2, so essentially, your code says cells(2).fontstyle.superscript








- Show quoted text -

Thanks mark. I tried your suggestion and it seems to work perfectly.
I knew it had to be something pretty simple but thanks again. Thank
you to everyone else who gave me sugestions as well.

Mattt
 
\> Public Function TestFont(cellAddress As Range) As Boolean
If cellAddress.Font.Superscript = True Then
TestFont = True
Else
TestFont = False
End If

End Function

No real need for the If-Then structure since you want to assign a Boolean to
TestFont and the left side of the logical expression evaluates to a
Boolean...

Public Function TestFont(cellAddress As Range) As Boolean
TestFont = cellAddress.Font.Superscript
End Function

Rick
 

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

Back
Top