Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default 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"
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare text in cell to custom text format?? Tommy[_4_] Excel Discussion (Misc queries) 1 July 20th 07 02:45 PM
Compare cells including formatting [email protected] Excel Programming 3 August 8th 06 01:04 AM
Compare two Sheets with Conditional Formatting wayliff Excel Discussion (Misc queries) 1 January 14th 06 12:26 AM
Compare two Sheets with Conditional Formatting wayliff Excel Discussion (Misc queries) 0 January 13th 06 08:15 PM
conditional formatting - compare 2 dates Dan Excel Discussion (Misc queries) 2 May 23rd 05 07:32 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"