周三,06 2021十月
  3 回复
  7.4K访问
0
投票
解开
我刚刚购买了 Kutools for Excel,因为我正在寻找一个选项,可以在 Excel 中仅复制选定区域的边框 - 保持目标区域的内容、格式、列宽不变。

我找到了一个解决方案 - 在此网页上使用 Kutools for Excel:
https://www.extendoffice.com/documents/excel/4336-excel-copy-borders-only.html#a1 

现在我尝试使用建议的宏,发现它根本没有做承诺的事情:
除了复制边界它还:
- 从目标区域中删除格式
- 更改目标区域的列
此外,宏的工作速度很慢,并且更改无法撤消。

你能帮我确保宏能实现所承诺的……吗?

期待您的回复

最棒的
玛丽安
0
投票
解开
嗨 MariannevanLubek,

抱歉,添麻烦了。 在这里,我们为案例编写了另一个宏。 你能试试吗?

Sub CopyBorders()
Dim xRg, yRg As Range
On Error Resume Next

Set xRg = Application.InputBox("Select Range with Borders to Copy...", "Kutools For Excel", , , , , , 8)
Set yRg = Application.InputBox("Select Cells to Apply Borders to range..", "Kutools For Excel", , , , , , 8)

With yRg.Borders(xlEdgeLeft)
.LineStyle = xRg.Borders(xlEdgeLeft).LineStyle
.ColorIndex = xRg.Borders(xlEdgeLeft).ColorIndex
.TintAndShade = xRg.Borders(xlEdgeLeft).TintAndShade
.Weight = xRg.Borders(xlEdgeLeft).Weight
End With
With yRg.Borders(xlEdgeTop)
.LineStyle = xRg.Borders(xlEdgeTop).LineStyle
.ColorIndex = xRg.Borders(xlEdgeTop).ColorIndex
.TintAndShade = xRg.Borders(xlEdgeTop).TintAndShade
.Weight = xRg.Borders(xlEdgeTop).Weight
End With
With yRg.Borders(xlEdgeBottom)
.LineStyle = xRg.Borders(xlEdgeBottom).LineStyle
.ColorIndex = xRg.Borders(xlEdgeBottom).ColorIndex
.TintAndShade = xRg.Borders(xlEdgeBottom).TintAndShade
.Weight = xRg.Borders(xlEdgeBottom).Weight
End With
With yRg.Borders(xlEdgeRight)
.LineStyle = xRg.Borders(xlEdgeRight).LineStyle
.ColorIndex = xRg.Borders(xlEdgeRight).ColorIndex
.TintAndShade = xRg.Borders(xlEdgeRight).TintAndShade
.Weight = xRg.Borders(xlEdgeRight).Weight
End With
With yRg.Borders(xlInsideHorizontal)
.LineStyle = xRg.Borders(xlInsideHorizontal).LineStyle
.ColorIndex = xRg.Borders(xlInsideHorizontal).ColorIndex
.TintAndShade = xRg.Borders(xlInsideHorizontal).TintAndShade
.Weight = xRg.Borders(xlInsideHorizontal).Weight
End With
With yRg.Borders(xlInsideVertical)
.LineStyle = xRg.Borders(xlInsideVertical).LineStyle
.ColorIndex = xRg.Borders(xlInsideVertical).ColorIndex
.TintAndShade = xRg.Borders(xlInsideVertical).TintAndShade
.Weight = xRg.Borders(xlInsideVertical).Weight
End With
End Sub


如果您有任何其他问题,请随时告诉我。

阿曼达
0
投票
解开
嗨 MariannevanLubek,

我要告诉你的一件事是,在你运行代码之后,你必须选择你想要应用边框的所有单元格,而不是一个单元格,就像下面的截图:
选择单元格.png

阿曼达
谢谢,在此期间,该问题已通过另一种方式解决。
  • 页:
  • 1
目前还没有回复。