当我在FOR LOOP中移动时,我试图在单个单元格周围放置一个边框,其中循环数由多少列中包含内容确定,列数在不同页面之间变化。
似乎我不能单独在动态单元格位置周围放置边框,而是必须指定范围或特定单元格。那是对的吗?
这是我用来完成目标的代码......
Sub Sheet_Formatting()
For Col_Count = 1 To Col_Count_Active_Sheet
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Interior.Color = RGB(100, 100, 100) ' sets to the color ???
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Borders.LineStyle.xlContinuous ' sets to the linestyle
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Borders.Weight.xlThick ' sets to the border thickness
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Font.Bold = True ' sets to the text format to bold
Next Col_Count
End Sub
我相信有一种方法可以完成边框规范,但我不能使用“Cells”来指定任何边框。内部颜色和字体根据需要工作。
答案 0 :(得分:2)
您需要为Border分配属性值,就像您为Color
和Bold
Sub Sheet_Formatting()
For Col_Count = 1 To Col_Count_Active_Sheet
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Interior.Color = RGB(100, 100, 100) ' sets to the color ???
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Borders.LineStyle = xlContinuous ' sets to the linestyle
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Borders.Weight = xlThick ' sets to the border thickness
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).Font.Bold = True ' sets to the text format to bold
Next Col_Count
End Sub
另外,另一种方式是:
ThisWorkbook.Worksheets(Active_Sheet).Cells(1, Col_Count).BorderAround (xlThin)
答案 1 :(得分:1)
Range.Borders属性与Border Object之间存在差异。不要混淆两者。
// if you are not using jQuery
var annyangBtn = document.querySelectorAll(".annyang-btn");
annyangBtn.addEventListener("click", annyang.start(), false);
我已用.Parent清理了一些重复的With ... End With statement引用。这不仅可以使代码更清晰,而且运行速度更快。