方法
打開要編輯的excel表
選中要復(fù)制的單元格
在菜單欄中選擇【視圖】
點(diǎn)擊【宏】
選擇【錄制宏】
取號(hào)名字后,點(diǎn)擊【確定】即開始錄制
然后在開發(fā)工具中點(diǎn)擊【停止錄制】,即錄制了一空白宏
最后按住【alt+f11】,打開一VBA窗口。在窗口中輸入以下代碼,按Alt+F11打開VBA界面,并將下述代碼更新在“個(gè)人宏工作簿”的模塊中。
Sub 多區(qū)域復(fù)制粘貼()On Error Resume Next
Dim SRange() As Range, UPRange As Range, TRange As Range
Dim i As Long, AreaNum As Long
Dim MinR As Long, MinC As Long
AreaNum = Selection.Areas.Count
ReDim SRange(1 To AreaNum)
MinR = ActiveSheet.Rows.Count
MinC = ActiveSheet.Columns.Count
For i = 1 To AreaNum
Set SRange(i) = Selection.Areas(i)
If SRange(i).Row < MinR Then MinR = SRange(i).Row
If SRange(i).Column < MinC Then MinC = SRange(i).Column
Next i
Set UPRange = Cells(SRange(1).Row, SRange(1).Column)
Set TRange = Application.InputBox(prompt:="選擇粘貼區(qū)域的最左上角單元格", Title:="多區(qū)域復(fù)制粘貼", Type:=8)
Application.ScreenUpdating = False
For i = 1 To AreaNum
SRange(i).Copy
TRange.Offset(SRange(i).Row - MinR, SRange(i).Column - MinC).PasteSpecial paste:=xlPasteValues
Next i
Application.ScreenUpdating = True
End Sub即可
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com