带有颜色的盒子的填充单元,作为用定义位置名称填充表的响应

发布于 2025-02-13 12:33:32 字数 218 浏览 3 评论 0原文

我是Excel宏的初学者。

如果我有一个表格,例如,与具有不同位置的单元格矩阵相对应的位置。我将如何创建一个宏,该宏根据I输入表中的位置(例如1,1:a)会为矩阵的相应单元格上色吗?

“在此处输入映像说明”

这可能很简单,但任何帮助/提示都会对此表示赞赏。

I am a beginner to excel macros.

If I have a table e.g. like this with positions that correspond to a matrix of cells with different positions. How would I create a macro that, based on the position I input into my table (e.g. 1,1:A), would color the corresponding cell of the matrix?

enter image description here

This might be really simple but any help/tips is appreciated.

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

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

发布评论

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

评论(1

猫七 2025-02-20 12:33:32

这是一个宏:

Sub test()
Dim cll As Range, txt As String, coordsX As String, coordsY As String
Dim i As Integer, j As Integer

    For Each cll In Range("A1:A14")
        txt = cll.Value
        coordsX = Mid(txt, _
                        WorksheetFunction.Find(":", txt) + 1, _
                        Len(txt) - WorksheetFunction.Find(":", txt) - Len(txt) + WorksheetFunction.Find(",", txt) - 1)
        coordsY = Right(txt, Len(txt) - WorksheetFunction.Find(",", txt))
        
        For i = 1 To WorksheetFunction.CountA(Range("E4:I5"))
            For j = 1 To WorksheetFunction.CountA(Range("D5:D11"))
                If Cells(j + 4, 3).Value = coordsY And Cells(4, i + 3).Value = coordsX Then
                    MsgBox Cells(j + 4, 3).Value & " " & Cells(4, i + 3).Value
                    Cells(j + 4, i + 3).Interior.Color = 500
                End If
            Next j
        Next i
    Next cll
    End Sub

范围A1:A14是这些坐标为(1:1,A ...)的范围;
范围E4:i5是表标头所在的地方(在这种情况下为数字);
范围D5:D11是行号的位置(在这种情况下为字母);

内饰500是背景的颜色代码。它也可以是RGB。

Here is a macro for that:

Sub test()
Dim cll As Range, txt As String, coordsX As String, coordsY As String
Dim i As Integer, j As Integer

    For Each cll In Range("A1:A14")
        txt = cll.Value
        coordsX = Mid(txt, _
                        WorksheetFunction.Find(":", txt) + 1, _
                        Len(txt) - WorksheetFunction.Find(":", txt) - Len(txt) + WorksheetFunction.Find(",", txt) - 1)
        coordsY = Right(txt, Len(txt) - WorksheetFunction.Find(",", txt))
        
        For i = 1 To WorksheetFunction.CountA(Range("E4:I5"))
            For j = 1 To WorksheetFunction.CountA(Range("D5:D11"))
                If Cells(j + 4, 3).Value = coordsY And Cells(4, i + 3).Value = coordsX Then
                    MsgBox Cells(j + 4, 3).Value & " " & Cells(4, i + 3).Value
                    Cells(j + 4, i + 3).Interior.Color = 500
                End If
            Next j
        Next i
    Next cll
    End Sub

Range A1:A14 is range where those coordinates are (1:1,A...);
Range E4:I5 is where table headers are (numbers in this case);
Range D5:D11 is where row numbers are (letters in this case);

Interior Color 500 is color code of background. It can be RGB too.

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