仅复制和粘贴可见单元格 [英] Copying and pasting visible cells only

查看:123
本文介绍了仅复制和粘贴可见单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要复制一列可见的单元格,然后粘贴到下一列.

I need to copy a column of visible cells and paste to the next column over.

我找不到有效的宏.我试了一下,但只复制了一些数字.

I can't find a macro that works. I had one going, but it only copies some numbers.

这是代码

Sub TryMe()
Sheet1.Range("A1:A100").SpecialCells(xlCellTypeVisible).Copy _
  Destination:=Range("A1").Offset(ColumnOffset:=1)
End Sub

此图像在运行宏之前.请注意隐藏的行.我需要这些数字才能复制到下一列.

This image is before I run the macro. Notice the rows that are hidden. I need these numbers to copy to the next column.

此图像是在我运行宏之后.我不明白为什么只复制一些数字.隐藏的行包含数字3和6.为什么它们出现在结果中,而不是可见的数字?我需要复制所见内容.

This image is after I run the macro. I don't understand why only some of the numbers are copying. The hidden rows contain the numbers 3 and 6. Why are they in the outcome, but not the visible numbers? I need to copy what is seen.

推荐答案

即使您手动执行此操作也无法做到这一点. 您将必须循环才能获得所需的内容.因此,请尝试一下.

You can't do it that way even if you manually do it.
You will have to loop to get what you want. So give this a try.

Dim c As Range
For Each c In Sheet1.Range("A1:A100").SpecialCells(xlCellTypeVisible)
    If Len(c) <> 0 Then c.Offset(0, 1) = c
Next

关于结果的奇怪之处在于为什么它以相反的顺序复制值.
我能理解它是否会复制B1以后的所有可见单元格,但不会反转值.
无论如何,如果可以,请尝试上面的方法.

The odd thing about your result is why does it copy the values in reverse order.
I can understand if it copies all the visible cells at B1 onwards, but not the reversal of values.
Anyways, try above first if it gets you going.

这篇关于仅复制和粘贴可见单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆