问题
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