Compare text formatting

P

potter.justin

I was wondering if there is a way to compare text formatting in excel
VBA. Basically I am creating a summary page in excel from an export
from another program. However, the exported document is poorly
formated, so I want to move cells around and whatnot based on the
format of a cell.

For an example if a cell has the same formatting as a specific cell,
then I want to move it (the specific cell is bold, italic, arial size
10).

How would you do this using VBA? I tried using something along the
lines of:

If ActiveSheet.Range("E" & i).NumberFormat =
ActiveSheet.Range_("E8").NumberFormat..... Then do some reformating

But I dont think that will work because the formatting is general for
both cells. Any help would be greatly appreciated.
 
H

Helmut Weber

Hi,

something along these lines:

Public Function SameFormat(s As Range, t As Range) As Boolean
' s = source range
' t = target range, the reference cell's range
SameFormat = True
If s.Font.Italic <> t.Font.Italic Then
SameFormat = False
Exit Function
End If
If s.Font.name <> t.Font.name Then
SameFormat = False
Exit Function
End If
If s.Font.Size <> t.Font.Size Then
SameFormat = False
Exit Function
End If
If s.Font.Bold <> t.Font.Bold Then
SameFormat = False
Exit Function
End If
' more if you like
End Function
' ---------------------
Sub Test5555()
MsgBox SameFormat(Cells(1, 1), Cells(1, 2))
End Sub

--

Helmut Weber

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
P

potter.justin

Hi,

something along these lines:

Public Function SameFormat(s As Range, t As Range) As Boolean
' s = source range
' t = target range, the reference cell's range
SameFormat = True
If s.Font.Italic <> t.Font.Italic Then
SameFormat = False
Exit Function
End If
If s.Font.name <> t.Font.name Then
SameFormat = False
Exit Function
End If
If s.Font.Size <> t.Font.Size Then
SameFormat = False
Exit Function
End If
If s.Font.Bold <> t.Font.Bold Then
SameFormat = False
Exit Function
End If
' more if you like
End Function
' ---------------------
Sub Test5555()
MsgBox SameFormat(Cells(1, 1), Cells(1, 2))
End Sub

--

Helmut Weber

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


I will try that thanks
 

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