ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Comparing formatting of two cells (https://www.excelbanter.com/excel-programming/343414-comparing-formatting-two-cells.html)

Chris B

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?

Rowan Drummond[_3_]

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?


Chris B

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?



Rowan Drummond[_3_]

Comparing formatting of two cells
 
You're welcome.

Chris B wrote:
Perfect! Thanks!

"Rowan Drummond" wrote:




All times are GMT +1. The time now is 02:09 AM.

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