如何在 Excel 中僅複製選定範圍的邊框?
在使用 Microsoft Excel 時,利用「選擇性粘貼」功能,可以輕鬆從一個區域中僅複製單元格的值、單元格格式、單元格公式等內容。但您是否嘗試過在 Excel 中僅複製某個範圍的邊框樣式呢?本文將向您展示如何在 Excel 中將選定範圍的邊框複製到新的範圍的方法。
使用 VBA 程式碼僅複製選定範圍的邊框
以下 VBA 程式碼可幫助您僅複製選定單元格的邊框樣式,然後將該邊框樣式應用於 Excel 中的新範圍。請按照以下步驟操作:
1. 按下「Alt」+「F11」鍵以打開「Microsoft Visual Basic for Applications」視窗背景色。
2. 在「Microsoft Visual Basic for Applications」視窗背景色中,點擊「插入」>「模組」,然後將以下 VBA 程式碼複製並粘貼到程式碼視窗中。
VBA 程式碼:僅複製選定範圍的邊框樣式於 Excel 中
Sub CopyBorders()
'Updated by Extendoffice 20211203
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 Cell 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
3. 按下「F5」鍵運行程式碼。在第一個彈出的「Kutools for Excel」對話框中,請選擇需要複製邊框的範圍,然後點擊「確定」按鈕。
4. 在第二個「Kutools for Excel」對話框中,請選擇要應用複製邊框的單元格,然後點擊「確定」按鈕。請參見截圖:
接著,您可以看見只有選定範圍的邊框樣式被複製並應用到新範圍,如下方截圖所示。
相關文章:
- 如何在 Excel 中複製並粘貼值時跳過重複項?
- 如何在 Excel 中複製單元格數據同時保留行高和列寬?
- 如何在 Excel 中將單元格作為文本值而不是公式進行複製?
- 如何在 Excel 中將數據複製到另一工作表的下一個空白行?
最佳 Office 生產力工具
🤖 | Kutools AI 助手:以智能執行為基礎,革新數據分析 |生成程式碼 | 創建自訂公式 | 分析數據並生成圖表 | 調用 Kutools 增強函數… |
熱門功能:查找、選取項目的背景色或標記重複值 | 刪除空行 | 合併列或單元格且不遺失數據 | 四捨五入(免公式)... | |
高級 LOOKUP:多條件 VLookup|多值 VLookup|多表查找|模糊查找... | |
高級下拉列表:快速創建下拉列表 |依賴型下拉列表 | 多選下拉列表... | |
列管理器:添加指定數量的列 | 移動列 | 切換隱藏列的顯示狀態 | 比較區域及列... | |
精選功能:網格聚焦 | 設計檢視 | 增強編輯欄 | 工作簿及工作表管理器 | 資源庫(快捷文本) | 日期提取器 | 合併資料 | 加密/解密儲存格 | 按列表發送電子郵件 | 超級篩選 | 特殊篩選(篩選粗體/傾斜/刪除線...)... | |
15 大工具集:12 項文本工具(添加文本、刪除特定字符…)|50+ 儀表 類型(甘特圖等)|40+ 實用 公式(基於生日計算年齡等)|19 項插入工具(插入QR码、根據路徑插入圖片等)|12 項轉換工具(金額轉大寫、匯率轉換等)|7 項合併與分割工具(高級合併行、分割儲存格等)|...及更多 |
運用 Kutools for Excel,全面提升您的 Excel 技能,體驗前所未有的高效。 Kutools for Excel 提供超過300 項進階功能,讓您提升工作效率、節省時間。 點此尋找您最需要的功能...
Office Tab 為 Office 帶來分頁介面,讓您的工作更加輕鬆簡單
- 在 Word、Excel、PowerPoint 中啟用分頁編輯與閱讀。
- 在同一視窗的新分頁中打開與創建多份文件,而非開啟新視窗。
- 提升您的生產力50%,每日可幫您減少數百次鼠標點擊!
所有 Kutools 外掛,一次安裝
Kutools for Office 套裝整合了 Excel、Word、Outlook 和 PowerPoint 的外掛,外加 Office Tab Pro,非常適合需要跨 Office 應用程式協同作業的團隊。





- 全合一套裝 — Excel、Word、Outlook及 PowerPoint 外掛 + Office Tab Pro
- 一鍵安裝,一份授權 — 幾分鐘完成設置(支援 MSI)
- 協同運作更順暢 — Office 應用間無縫提升生產力
- 30 天全功能試用 — 無需註冊、無需信用卡
- 最超值 — 一次購買,節省單獨外掛費用