ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compare text formatting (https://www.excelbanter.com/excel-programming/388340-compare-text-formatting.html)

[email protected]

Compare text formatting
 
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.


Helmut Weber[_2_]

Compare text formatting
 
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"

[email protected]

Compare text formatting
 
On Apr 28, 1:22 pm, Helmut Weber wrote:
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



All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com