Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Comparing formatting of two cells
Situation: Two cells contain the same text, and have the strikethrough format
applied to different subsets of the text. Example: Cell 1: THE QUICK BROWN FOX <start strikethrough JUMPED OVER <end strkethrough THE LAZY DOG. Cell 2: THE <start strikethrough QUICK BROWN <end strikethrough FOX JUMPED OVER <end strkethrough THE LAZY DOG. If the whole cell has the Strikethrough font attribute applied, then Cell.Font.Strikethrough is True. If none of it has the Strikethrough attribute applied, then Cell.Font.Strikethrough is False. If only some of it has the attribute applied, as in the examples above, then Cells.Font.Strikethrough is Null. Is there some way VBA can compare two cells formatted in the examples above and identify that there is a difference between them? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Comparing formatting of two cells
Maybe like this:
Sub ChkCells() Dim i As Integer Dim Same As Boolean Dim Cell1 As Range Dim Cell2 As Range Same = True Set Cell1 = Range("A1") '<<Set as required Set Cell2 = Range("A3") '<<Set as required If Len(Cell1.Value) < Len(Cell2.Value) Or _ Cell1.Value < Cell2.Value Then Same = False Else For i = 1 To Len(Cell1.Value) If Cell1.Characters(i, 1).Font.Strikethrough < _ Cell2.Characters(i, 1).Font.Strikethrough Then Same = False Exit For End If Next i End If If Same Then MsgBox "The cells have the same strikethrough" Else MsgBox "The cells have different strikethrough" End If End Sub Hope this helps Rowan Chris B wrote: Situation: Two cells contain the same text, and have the strikethrough format applied to different subsets of the text. Example: Cell 1: THE QUICK BROWN FOX <start strikethrough JUMPED OVER <end strkethrough THE LAZY DOG. Cell 2: THE <start strikethrough QUICK BROWN <end strikethrough FOX JUMPED OVER <end strkethrough THE LAZY DOG. If the whole cell has the Strikethrough font attribute applied, then Cell.Font.Strikethrough is True. If none of it has the Strikethrough attribute applied, then Cell.Font.Strikethrough is False. If only some of it has the attribute applied, as in the examples above, then Cells.Font.Strikethrough is Null. Is there some way VBA can compare two cells formatted in the examples above and identify that there is a difference between them? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Comparing formatting of two cells
Perfect! Thanks!
"Rowan Drummond" wrote: Maybe like this: Sub ChkCells() Dim i As Integer Dim Same As Boolean Dim Cell1 As Range Dim Cell2 As Range Same = True Set Cell1 = Range("A1") '<<Set as required Set Cell2 = Range("A3") '<<Set as required If Len(Cell1.Value) < Len(Cell2.Value) Or _ Cell1.Value < Cell2.Value Then Same = False Else For i = 1 To Len(Cell1.Value) If Cell1.Characters(i, 1).Font.Strikethrough < _ Cell2.Characters(i, 1).Font.Strikethrough Then Same = False Exit For End If Next i End If If Same Then MsgBox "The cells have the same strikethrough" Else MsgBox "The cells have different strikethrough" End If End Sub Hope this helps Rowan Chris B wrote: Situation: Two cells contain the same text, and have the strikethrough format applied to different subsets of the text. Example: Cell 1: THE QUICK BROWN FOX <start strikethrough JUMPED OVER <end strkethrough THE LAZY DOG. Cell 2: THE <start strikethrough QUICK BROWN <end strikethrough FOX JUMPED OVER <end strkethrough THE LAZY DOG. If the whole cell has the Strikethrough font attribute applied, then Cell.Font.Strikethrough is True. If none of it has the Strikethrough attribute applied, then Cell.Font.Strikethrough is False. If only some of it has the attribute applied, as in the examples above, then Cells.Font.Strikethrough is Null. Is there some way VBA can compare two cells formatted in the examples above and identify that there is a difference between them? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Comparing formatting of two cells
You're welcome.
Chris B wrote: Perfect! Thanks! "Rowan Drummond" wrote: |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Comparing three columns, Conditional Formatting | New Users to Excel | |||
Conditional formatting comparing two columns | Excel Worksheet Functions | |||
Conditional formatting comparing times | Excel Worksheet Functions | |||
Comparing two lists using Conditional Formatting | Excel Worksheet Functions | |||
Conditional formatting/ comparing worksheets | Excel Discussion (Misc queries) |