简体   繁体   中英

Excel VBA Macro Recording Skip Blank Copied repeated paste

Halo Everyone What i'm trying to do is to copy filled cell in c6:d20 and skip the blank cell but the result when i paste i only got the d6:d20 maybe because in column C is formula filled

Here is my first record macro edit

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

any help would be nice Thank you

If you only want to copy-paste value without formula the following might help

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

NOTE : You should avoid using SELECT . See this for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM