如果该行中的一个单元格有红色文本,则为单元格着色

发布于 2025-02-09 06:29:00 字数 152 浏览 1 评论 0 原文

我通常会合并Excel文件输入,并检查是否发生了变化,人们以红色的单元格中突出显示。这意味着我必须从视觉上滚动整个Excel文件才能搜索这些红色单元格,以便丢失它们。 如果行中的单元格中有红色文本(或不是默认黑色的文本),是否可以在Visual Basic中将格式应用于行? 先感谢您 卡门

I usually merge excel files inputs and to check if there has been a change, the people highlight in red the modifiied cells. This means that I have to scroll visually the whole Excel file to search for these red cells with the risk of missing them.
Is there a way in visual basic to apply a formatting to the rows if a cell in the row has a red text (or a text that is not the default black)?
Thank you in advance
Carmen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清音悠歌 2025-02-16 06:29:00

1。 在此处解决的所有文本都

在此处解决:
根据其他单元格的字体颜色更改单元格的值

2。查找带有红色的文本的单元格

您在此处找到的起点我如何在excel vba中的单元格中找到一个单词并为红色染色(只有整个单词不是整个单词使用VBA代码?
在此处完成了每个字符的检查:

3。创建用户定义的功能

如果您创建一个用户定义的函数以搜索所需的格式,则可以过滤这些特定行。 (请参阅上面的nr1。link)
例如,它看起来像 = ifcoloredCells(a2:e2,“”,“ no Change”)

4。将更改应用于过滤的数据

过滤后的更改数据后,您可以根据您的whishes修改格式或数据。

1. Find cells which have all the text colored in red

Similar question solved here:
Change the value of the cell according to the font colour of the other cell

2. Find cells which have text partially colored in red

A starting point you find here How can I find a word in a cell in Excel VBA and color it red (only the word not the entire cell) using VBA code?
A check for every single character was done here: https://answers.microsoft.com/en-us/msoffice/forum/all/need-help-to-find-text-with-partial-font-color/b8e58634-b114-42fa-8f5f-fb83d9d3746d

3. create a user defined function

If you create a user defined function to search for the desired formatting you can filter for these specific rows. (see link at nr 1. above)
e.g. it could look like =ifColoredCells(A2:E2," ","no changes")

4. apply changes to filtered data

After filtering for the changed data you can either modify the format or the data according to your whishes.

enter image description here

左岸枫 2025-02-16 06:29:00

尝试以下代码:

Sub SubRedRows()
    
    'Declarations.
    Dim RngData As Range
    Dim RngTarget As Range
    Dim DblStart As Double
    Dim StrAddress As String
    
    'Settings.
    Set RngData = Range("A1:J10")
    Set RngTarget = RngData(1, 1)
    
    'Setting the format to be searched.
    Application.FindFormat.Clear
    Application.FindFormat.Font.Color = vbRed
    
    'Covering the whole RngData.
    Do
        
        'Setting RngTarget as the first cell after RngTarget with the desired format.
        Set RngTarget = Cells.Find(What:="", _
                                   After:=RngTarget, _
                                   LookIn:=xlFormulas, _
                                   LookAt:=xlPart, _
                                   SearchOrder:=xlByRows, _
                                   SearchDirection:=xlNext, _
                                   MatchCase:=False, _
                                   SearchFormat:=True _
                                  )
        
        'Checking if DblStart has been already set.
        If DblStart = 0 Then
            'If RngTarget is nothing, no range with the desired format has been found so the macro is terminated
            If RngTarget Is Nothing Then Exit Sub
            'Setting DblStart.
            DblStart = RngTarget.row
        Else
            'If RngTarget's row is equal to DblStart, the loop is left.
            If RngTarget.row = DblStart Then GoTo CP_Exit_Loop
        End If
        
        'Adding the address of the row of the cell just found to StrAddress.
        StrAddress = StrAddress & "," & Intersect(RngTarget.EntireRow, RngData).Address
        
        'Setting RngTarget for the next row.
        Set RngTarget = Cells(RngTarget.row + 1, 1)
    Loop
    
CP_Exit_Loop:
    
    'Setting the format of the range found.
    Range(Right(StrAddress, Len(StrAddress) - 1)).Font.Color = vbRed
    
    'Clearing up the find format.
    Application.FindFormat.Clear
    
End Sub

您需要根据需要更改RNGDATA的设置。它即使在具有多个区域的范围内也可以工作(即使只有其中一个相交中只有一个具有红色字体的单元格,它仍然会使所有与给定行和任何区域的相交的字体红色变为红色)。

Try this code:

Sub SubRedRows()
    
    'Declarations.
    Dim RngData As Range
    Dim RngTarget As Range
    Dim DblStart As Double
    Dim StrAddress As String
    
    'Settings.
    Set RngData = Range("A1:J10")
    Set RngTarget = RngData(1, 1)
    
    'Setting the format to be searched.
    Application.FindFormat.Clear
    Application.FindFormat.Font.Color = vbRed
    
    'Covering the whole RngData.
    Do
        
        'Setting RngTarget as the first cell after RngTarget with the desired format.
        Set RngTarget = Cells.Find(What:="", _
                                   After:=RngTarget, _
                                   LookIn:=xlFormulas, _
                                   LookAt:=xlPart, _
                                   SearchOrder:=xlByRows, _
                                   SearchDirection:=xlNext, _
                                   MatchCase:=False, _
                                   SearchFormat:=True _
                                  )
        
        'Checking if DblStart has been already set.
        If DblStart = 0 Then
            'If RngTarget is nothing, no range with the desired format has been found so the macro is terminated
            If RngTarget Is Nothing Then Exit Sub
            'Setting DblStart.
            DblStart = RngTarget.row
        Else
            'If RngTarget's row is equal to DblStart, the loop is left.
            If RngTarget.row = DblStart Then GoTo CP_Exit_Loop
        End If
        
        'Adding the address of the row of the cell just found to StrAddress.
        StrAddress = StrAddress & "," & Intersect(RngTarget.EntireRow, RngData).Address
        
        'Setting RngTarget for the next row.
        Set RngTarget = Cells(RngTarget.row + 1, 1)
    Loop
    
CP_Exit_Loop:
    
    'Setting the format of the range found.
    Range(Right(StrAddress, Len(StrAddress) - 1)).Font.Color = vbRed
    
    'Clearing up the find format.
    Application.FindFormat.Clear
    
End Sub

You'll need to change the setting of RngData accordingly to your need. It will work even on ranges with multiple areas (still it will turn the font red on all the intersections with a given row and any area even if only one of those intersection has 1 or more cells with red font).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文