VBA将不同工作表的格式条件转换为循环

时间:2018-04-13 18:36:53

标签: vba excel-vba loops for-loop excel

我正在寻找一种方法将以下格式条件转换为循环以提高编码效率。我想过将Table放在一个数组中,但是对于重复的表名,似乎并没有太大改进。

条件格式非常简单。它只是突出显示值在5到10和-5到-10之间的单元格。

任何见解都会有所帮助!

 #include<iostream>
 using namespace std;
 class C1;
 class C2
 {
      int x;
 public:
     operator C2()
     {
       C2 temp;
       cout<<"operator function called"<<endl;
       return temp;
    }
 };
class C1
{
   int x;
public:
   C1():x(10){}
   C1(C2)
  {
    cout<<"constructor called"<<endl;
  }
};
 int main()
{
  C1 obj1;
  C2 obj2;
  obj1=obj2;
}

1 个答案:

答案 0 :(得分:2)

尝试:

Sub test()

Dim xl_sheet As Worksheet

For Each xl_sheet In ActiveWorkbook.Worksheets

    If xl_sheet.Name Like "Table*" Then

    With xl_sheet
    .Range("P:P").FormatConditions.Add(Type:=xlCellValue, Operator:=xlBetween, Formula1:="=5", Formula2:="10").Interior.Color = rgbYellow
    .Range("P:P").FormatConditions.Add(Type:=xlCellValue, Operator:=xlBetween, Formula1:="=-5", Formula2:="-10").Interior.Color = rgbYellow
    End With

    End If


 Next xl_sheet

End Sub