PC Review


Reply
Thread Tools Rate Thread

Compare text formatting

 
 
potter.justin@gmail.com
Guest
Posts: n/a
 
      28th Apr 2007
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.

 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      28th Apr 2007
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"
 
Reply With Quote
 
potter.justin@gmail.com
Guest
Posts: n/a
 
      28th Apr 2007
On Apr 28, 1:22 pm, Helmut Weber <nbhymsjxd...@mailinator.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Conditional formatting to compare two strings.... s.vanderford@gmail.com Microsoft Access Form Coding 2 4th Jan 2007 03:57 PM
Conditional Formatting to Compare to Lists John Michl Microsoft Excel Worksheet Functions 3 7th Jun 2006 04:15 PM
Compare two Sheets with Conditional Formatting wayliff Microsoft Excel Misc 1 14th Jan 2006 12:26 AM
Compare two Sheets with Conditional Formatting wayliff Microsoft Excel Misc 0 13th Jan 2006 08:15 PM
Compare string, wildcard, text/cell formatting 0-0 Wai Wai ^-^ Microsoft Excel Discussion 12 7th Sep 2005 06:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.