to copy data in excel and omit blank cells

Hi,

Could you provide me a macro which copies data from a specific range to a specific range and omit the blank cells while copying ?

Please find enclosed sample of the data and the needed  format.

Thanks
Alcuino
data.xlsx
alcuinoAsked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
Try this:
Sub DoCopy()
   With Range("A1:L5")
      .Copy Range("P1")
      Range("P1").Resize(.Rows.Count, .Columns.Count).SpecialCells(xlCellTypeBlanks).Delete shift:=xlShiftToLeft
   End With
End Sub

Open in new window

0
 
Rob HensonFinance AnalystCommented:
Do you need the blank cells actually omitted or do you want to avoid overwriting existing data because of blank cells in the source data?

If the latter, you can do a paste special and tick the box for Skip Blanks. You can then copy the whole range and paste in one go but where the copied range was blank it will not paste anything into the destination range.

Cheers
Rob H
0
All Courses

From novice to tech pro — start learning today.