【问题标题】:Trying to add all borders to range with variable row count in excel vba尝试在excel vba中将所有边框添加到具有可变行数的范围内
【发布时间】:2017-03-20 02:41:06
【问题描述】:

我正在尝试将所有边框添加到我拥有的标题下方的内容中。范围是 A7 到 Ox,其中 x 是内容的最后一行。列出的代码的第一部分查找 CFS-GHOST-DJKT 并删除运行良好的行。我不确定如何正确选择下端行。

Dim x As Long
For x = Cells(Rows.Count, "A").End(xlUp).Row To 7 Step -1
    If Cells(x, "A") = "CFS-GHOST-DJKT" Then Rows(x).Delete


'Add Gridlines=========================================================


      Range(A7, Ox).Select
      With Selection.Borders
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin

      End With

【问题讨论】:

    标签: vba excel border


    【解决方案1】:

    使用 Range(A7, Ox) 的术语告诉 VBA 选择由变量的 Address 定义的矩形区域(类型为 Range)A7 作为一个角和变量的 Address(也类型为Range) Ox 作为另一个角。

    由于您没有定义这些变量,您的代码将失败。

    试试这个:

    Dim x As Long
    For x = Cells(Rows.Count, "A").End(xlUp).Row To 7 Step -1
        If Cells(x, "A") = "CFS-GHOST-DJKT" Then Rows(x).Delete
    Next
    
    With Range("A7:O" & Cells(Rows.Count, "A").End(xlUp).Row).Borders
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 2017-11-15
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      相关资源
      最近更新 更多