根据选择 - 合并的单元格参考其他单元格

发布于 2025-01-29 20:04:18 字数 790 浏览 1 评论 0原文

我在工作表中参考其他单元格时有问题。我有一个VBA,可以用枢轴表创建桌子,并将它们保存在不同的床单上。表的示例:

“在此处输入图像描述”

任何名称的行数都可以更改,因此总排位置也可以更改。我需要大胆整个小计和总行 (在这种情况下,它将是b9:g9,b12:g12,b14:g14,a15:g15)所以我尝试了一下:

           If Right(cell.Value, 5) Like "Total" Then
                  With cell
                  .HorizontalAlignment = xlLeft
                  .Font.Bold = True
                    End With
                    End If
                Next cell

自然而然地向其中包含“总体”文本的一个单元格。问题是在我想粗体的行中引用其他单元格 - 合并后的单元格在搞砸了。当我尝试此操作时:

cell.EntireRow.Font.Bold = True

整个项目都大胆(A5:G14)。我还尝试了偏移函数,但是偏移量(0,1)将我发送到Cell C5。

您是否知道如何使整个总和小行大胆?

谢谢, B

I have a problem with referencing to other cells in my sheet. I have a VBA that creates tables out of a pivot table and saves them on different sheets. Example of the table:

enter image description here

The number of rows for any name can change, the total row position can therefore change too. I needed to bold the whole subtotal and total rows
(in this case it would be B9:G9, B12:G12, B14:G14, A15:G15) so I tried this:

           If Right(cell.Value, 5) Like "Total" Then
                  With cell
                  .HorizontalAlignment = xlLeft
                  .Font.Bold = True
                    End With
                    End If
                Next cell

which naturally only bolded the one cell which has the 'Total' text in it. The problem is referencing to the other cells in the rows I want to bold - the merged cells are messing that up. When I tried this:

cell.EntireRow.Font.Bold = True

the whole Project got bold (A5:G14). I also tried the offset function, but offset(0,1) sent me to cell C5.

Do you please have any idea how to make the whole total and subtotal rows bold?

Thanks,
B.

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

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

发布评论

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

评论(1

梦中的蝴蝶 2025-02-05 20:04:18

您可以做这样的事情:

Sub Tester()
    Dim ws As Worksheet, c As Range
    
    Set ws = ActiveSheet
    For Each c In ActiveSheet.UsedRange.Cells
        If c.Value Like "*Total" Then
            'from cell with "*Total" to last column
            With ws.Range(c, ws.Cells(c.Row, "G"))
                .HorizontalAlignment = xlLeft
                .Font.Bold = True
            End With
        End If
    Next c
End Sub

You could do something like this:

Sub Tester()
    Dim ws As Worksheet, c As Range
    
    Set ws = ActiveSheet
    For Each c In ActiveSheet.UsedRange.Cells
        If c.Value Like "*Total" Then
            'from cell with "*Total" to last column
            With ws.Range(c, ws.Cells(c.Row, "G"))
                .HorizontalAlignment = xlLeft
                .Font.Bold = True
            End With
        End If
    Next c
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文