Use VBA to copy all visible and non-empty cells in a range

淺唱寂寞╮ 提交于 2020-01-03 04:32:14

问题


After filtering, I want to copy all visible and non-empty cells (the cells which contain text). For some reason, my current code isn't working. Any help would be greatly appreciated. Thanks!

  Sheets("Sheet1").Range("S2:S5000").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy

回答1:


Full admission that I did not try your code, but you can also try the following

With Sheets("Sheet1").Range("S2:S5000")
    Application.Intersect(.SpecialCells(xlCellTypeVisible), _
                       .SpecialCells(xlCellTypeConstants)).Copy
End With

Making the open ended assumption that the reason for copying is to paste somewhere else, you can update the above code by using

With Sheets("Sheet1").Range("S2:S5000")
    Application.Intersect(.SpecialCells(xlCellTypeVisible), _
          .SpecialCells(xlCellTypeConstants)).Copy _
               Destination:= Sheets("destSheet").Range("destRange")
End With


来源:https://stackoverflow.com/questions/18625468/use-vba-to-copy-all-visible-and-non-empty-cells-in-a-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!