【问题标题】:Conditional Formatting and text: Based on a condition I want to copy the format of another cell条件格式和文本:根据条件我想复制另一个单元格的格式
【发布时间】:2016-03-07 02:02:41
【问题描述】:

在excel中

我正在尝试根据某些条件复制另一个单元格的元素和单元格格式。

G12 = (If C10 = C11, *Leave Blank, If (C10>C11, *Copy the elements and format of B10, *Copy the elements and format of B11))

我已经尝试过这个功能并成功复制了元素,但也无法更改格式。我用过:

=IF($C$10=$C$11,"",IF($C$10>$C$11,B10,B11))

我了解了条件格式,但没有看到基于某些条件复制另一个单元格格式的方法。必须指定颜色。

感谢您的帮助!

tl:dr

March Madness Example

弗吉尼亚以 76 比 75 击败 UNC

我想将 Copy (1) Virginia 复制到括号中具有石灰绿色背景的下一个位置。如果 UNC 获胜,我希望 (16) UNC 和玫瑰色复制到下一个括号位置

【问题讨论】:

    标签: excel conditional-formatting vba


    【解决方案1】:

    转到 vb-editor (Alt + F11),插入新模块并粘贴此代码:

    Function RangeSelectionPrompt(txt As String) As Range
        Dim rng As Range
        Set rng = Application.InputBox(txt, "Select a range", Type:=8)
    
        Set RangeSelectionPrompt = rng
    End Function
    
    Sub FormatAs()
    
        Dim Sh As Worksheet
        Dim r1 As Range, r2 As Range
        Dim txt1 As String, txt2 As String
        Dim cel As Range, Col As Range
        Dim Val, check As Long, pos As Long
    
        Set Sh = ActiveSheet
    
        txt1 = "Enter Range #1 - sourse"
        txt2 = "Enter Range #2 - to paste formats"
    
        Set r1 = Intersect(RangeSelectionPrompt(txt1), Sh.UsedRange)
        Set r2 = Intersect(RangeSelectionPrompt(txt1), Sh.UsedRange)
    
    
        For Each cel In r2.Cells
    
            Val = cel.Value
    
            If Val <> "" Then
    
                For Each Col In r1.Columns
    
                    check = WorksheetFunction.CountIf(Col, Val)
    
                    If check > 0 Then
                        pos = WorksheetFunction.Match(Val, Col, 0)
    
                        Col.Cells(pos, 1).Copy
                        cel.PasteSpecial Paste:=xlPasteFormats
    
                    End If
    
                Next Col
    
            End If
    
        Next cel
    
    End Sub
    

    运行一次即可复制格式。您需要定义两个范围:

    源范围 (A:B) 和要粘贴的范围 (F:G)

    【讨论】:

    • 马克斯,感谢您的回复。不幸的是,这看起来并不是我正在寻找的功能。我一直在与 Microsoft 支持部门取得联系,看来我正在寻找的那种功能是不可能的。基本上,我一直在寻找一个可以复制值(文本)和格式(填充颜色和边框)的条件函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多