2017-09-28 270 views
0

光環所有人 我想要做的是複製c6中的填充單元格:d20並跳過空白單元格 但結果當我粘貼時只有d6:d20 也許是因爲列C是式充滿Excel VBA宏錄製跳過空白複製重複的粘貼

這是我的第一個記錄的宏編輯

Sub RoundedRectangle1_Click() 
' 
' RoundedRectangle1_Click Macro 
' 

' 
Sheets("Resume").Select 
Range("C6:D20").Select 
Selection.SpecialCells(xlCellTypeConstants).Copy 
Sheets("Input").Select 
Range("A" & Rows.Count).End(xlUp).Offset(1).Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
    :=False, Transpose:=False 
End Sub 

任何幫助將是不錯 謝謝

+0

你在哪裏粘貼你的數據? –

+0

在另一張表格(「輸入」) –

回答

0

如果你只想要到c沒有公式OPY粘貼值以下可能有助於

Sub RoundedRectangle1_Click() 
    Dim srcSht As Worksheet, destSht As Worksheet 
    Dim srcRng As Range, destRng As Range 

    Set srcSht = ThisWorkbook.Sheets("Resume") 'this is your input sheet 
    Set destSht = ThisWorkbook.Sheets("Input") 'this is your output sheet 

    Set srcRng = srcSht.Range("C6:D20")   'set range to be copied 
    Set destRng = destSht.Range("A" & destSht.Rows.Count).End(xlUp).Offset(1).Resize(srcRng.Rows.Count, srcRng.Columns.Count) 'set range to paste 
    destRng.Value = srcRng.Value    'copy only values 
    destRng.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp 'delete blnk cells 
End Sub 

注:您應該避免使用SELECT。有關詳細信息,請參見this

+0

You Rock ..這解決了我的問題..謝謝@ Mrig,順便說一句我如何標記人? –

+0

@TriKuntartoKunKun - 不客氣! – Mrig