<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBA: поиск и форматирование части текста ячейки в Excel]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=2550&amp;type=atom" />
	<updated>2008-12-06T11:09:03Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=2550</id>
		<entry>
			<title type="html"><![CDATA[VBA: поиск и форматирование части текста ячейки в Excel]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=16797#p16797" />
			<content type="html"><![CDATA[<p>Макрос ищет в таблице Excel на текущем листе латинские символы и выделяет их красным цветом, но не всю ячейку и не всё слово, и именно латинскую букву. То есть, если встретится слово &quot;прNвет&quot; - покрасит букву N. Пример можно использовать и для работы с выделенным диапазоном, см. комментарии в коде.</p><p>Потребуется подключить библиотеку &quot;Microsoft VBScript Regular Expressions&quot;, в редакторе Visual Basic меню &quot;Tools&quot; - &quot;References...&quot;.<br /></p><div class="codebox"><pre><code>Option Explicit

Sub MyCharFormat()
    Dim objRegExp As New RegExp
    Dim objCell As Range
    Dim collMatches As MatchCollection
    Dim objMatch As Match
    
                
    With objRegExp
        .Pattern = &quot;[a-z]&quot;
        .IgnoreCase = True
        .MultiLine = False
        .Global = True
    End With
    
    &#039; Работаем со всем рабочим листом
    For Each objCell In ActiveWorkbook.ActiveSheet.UsedRange.Cells
    &#039; или…
    &#039; Работаем с выделенным диапазоном. Используем Shift и Ctrl
    &#039; для множественного выделения диапазона из нескольких областей.
    &#039;For Each objCell In Application.Selection.Cells
        With objCell
            If Not (IsEmpty(.Value) Or IsNull(.Value) Or IsError(.Value)) Then
                Application.StatusBar = &quot;Testing Cell(&quot; &amp; CStr(.Row) &amp; &quot;,&quot; &amp; CStr(.Column) &amp; &quot;)…&quot;
        
                If objRegExp.Test(.Value) Then
                    Set collMatches = objRegExp.Execute(.Value)
             
                    For Each objMatch In collMatches
                        With .Characters(objMatch.FirstIndex + 1, 1).Font
                            .ColorIndex = 3
                        End With
                    Next objMatch
                End If
            End If
        End With
    Next objCell
    
    Application.StatusBar = False
End Sub</code></pre></div><p>Автор примера - <strong>alexii</strong>.</p>]]></content>
			<author>
				<name><![CDATA[The gray Cardinal]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2</uri>
			</author>
			<updated>2008-12-06T11:09:03Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=16797#p16797</id>
		</entry>
</feed>
