[英]Trying to add all borders to range with variable row count in excel vba
I am trying to add all borders to the contents below the headers that I have. 我试图将所有边框添加到我具有的标题下面的内容中。 The range would be A7 to Ox where x is the last row of content. 范围是A7到Ox,其中x是内容的最后一行。 The first part of the code listed looks for CFS-GHOST-DJKT and deletes the row which works perfectly. 列出的代码的第一部分寻找CFS-GHOST-DJKT并删除行得很好的行。 I am unsure about how to select the lower ending row correctly. 我不确定如何正确选择下端行。
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
Using a term of Range(A7, Ox)
is telling VBA to select the rectangular area defined by the Address
of the variable (of type Range
) A7
as one corner and the Address
of the variable (also of type Range
) Ox
as the other corner. 使用的术语Range(A7, Ox)
告诉VBA选择由所限定的矩形区域Address
的变量的(类型的Range
) A7
和作为一个角的Address
的变量(也的类型的Range
) Ox
与其他角。
As you have defined neither of those variables, your code fails. 由于您都没有定义这些变量,因此代码将失败。
Try this instead: 尝试以下方法:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.