围绕每个单元格在一个范围内 [英] Border around each cell in a range
问题描述
我正在尝试创建一个简单的函数,它将在一定范围内的每个单元格周围添加边框。使用美妙的录音,这会产生大量的代码,这是非常无用的。下面的代码将显示一个数据表,围绕这个范围内的每个单元格,我想添加一个边框。在线我没有找到一个简单或明确的答案。
所有的帮助是非常感谢!
设置DT =表(DATA)
endRow = DT.Range(F& Rows.Count).End(xlUp).Row
result = 3
对于I = 2 To endRow
如果DT.Cells(I,6).Value = Range(B1)。然后
Range(一个&结果)= DT.Cells(I,6).Value
Range(B& result)= DT.Cells(I,1).Value
Range(C & result)= DT.Cells(I,24).Value
Range(D& result)= DT.Cells(I,37).Value
Range(E&结果)= DT.Cells(I,3).Value
Range(F& result)= DT.Cells(I,15).Value
Range(G& result) = DT.Cells(I,12).Value
Range(H& result)= DT.Cells(I,40).Value
Range(I& result)= DT .Cells(I,23).Value
result = result + 1
End If
Next I
您只需要一行代码来围绕范围内的每个单元格设置边框:
Range( A1:F20)。Borders.LineStyle = xlContinuous
将多个效果应用于每个单元格的边框也很容易。 >
例如:
Sub RedOutlineCells()
Dim rng As范围
设置rng =范围(A1:F20)
带rng.Borders
.LineStyle = xlContinuous
.Color = vbRed
.Weight = xlThin
End with
End Sub
I am trying to create a simple function that will add borders around every cell in a certain range. Using the wonderful recording this generates a ton of code which is quite useless. The code below will display a 'table' of data, around each cell in this range I would like to add a border. Online I haven't been able to find a simple or clear answer for this.
All help is much appreciated!
Set DT = Sheets("DATA")
endRow = DT.Range("F" & Rows.Count).End(xlUp).Row
result = 3
For I = 2 To endRow
If DT.Cells(I, 6).Value = Range("B1").Value Then
Range("A" & result) = DT.Cells(I, 6).Value
Range("B" & result) = DT.Cells(I, 1).Value
Range("C" & result) = DT.Cells(I, 24).Value
Range("D" & result) = DT.Cells(I, 37).Value
Range("E" & result) = DT.Cells(I, 3).Value
Range("F" & result) = DT.Cells(I, 15).Value
Range("G" & result) = DT.Cells(I, 12).Value
Range("H" & result) = DT.Cells(I, 40).Value
Range("I" & result) = DT.Cells(I, 23).Value
result = result + 1
End If
Next I
You only need a single line of code to set the border around every cell in the range:
Range("A1:F20").Borders.LineStyle = xlContinuous
It's also easy to apply multiple effects to the border around each cell.
For example:
Sub RedOutlineCells()
Dim rng As Range
Set rng = Range("A1:F20")
With rng.Borders
.LineStyle = xlContinuous
.Color = vbRed
.Weight = xlThin
End With
End Sub
这篇关于围绕每个单元格在一个范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!