简体   繁体   English

基于查询表中的单元格值使整行加粗的 VBA 代码

[英]VBA Code for Making Entire Rows Bold based on a Cell value in the Query table

I have a table in the range (G15:AL540) generated through SAP Query .我有一个通过 SAP Query 生成的范围 (G15:AL540) 中的表。 I need to make all the rows Bold , if the Cells in Column L Contains the word "Main Investigation".如果 L 列中的单元格包含“主要调查”一词,我需要将所有行设为 Bold 。 I did it using Conditional Formatting ( =$L16="Main investigation") and it worked.我使用条件格式(=$L16="主要调查")做到了,并且奏效了。 But I need to write it in VBA , so that this formatting is applied automatically when the Query is refreshed.但是我需要在 VBA 中编写它,以便在刷新查询时自动应用此格式。

Thanks!谢谢!

This will only work for active sheet, change activesheet to sheets("sheetabc") to reference another sheet这仅适用于活动工作表,将活动工作表更改为工作表(“sheetabc”)以引用另一张工作表

Sub test()
With ActiveSheet
    For Each cell In .Range("G15:" & .Range("G15").End(xlDown).Address)
        If .Cells(cell.Row, 12).Value = "Main investigation" Then
            cell.EntireRow.Font.Bold = True
        End If
    Next
End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM