仅复制并粘贴excel vba中的非n#a单元格

时间:2016-11-10 15:39:02

标签: excel vba excel-vba

如何在没有#N / A数据的情况下将列数据A复制并粘贴到B列。

我在A列中有数据

A          B

8a61     8a61
#N/A      fs
fs       fttt
fttt     dsff
#N/A
dsff

复制粘贴我使用的非空白单元格

  Set wb = ActiveWorkbook
  Set ws1 = wb.Sheets("Sheet7")
  ws1.Range("A1:A1000").SpecialCells(xlCellTypeConstants).Copy  ws1.Range("B1")

如何在没有#N / A

的情况下复制粘贴列数据

2 个答案:

答案 0 :(得分:0)

给它一个去,显然需要放入一个sub()

Dim i As Integer, j As Integer
j = 1
For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If Not IsError(Cells(i, 1).Value) Then
    Cells(j, 4) = Cells(i, 1)
    j = j + 1
End If
Next i

答案 1 :(得分:0)

Dim rng As Range     Dim crange As Range     Dim lastrow As Double

Sheets("Sheet1").AutoFilterMode = False

Set rng = Range("A1", Range("A2").End(xlDown))
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set crange = Range("A2:A" & lastrow)
rng.AutoFilter field:=1, Criteria1:="<>#N/A"

crange.SpecialCells(xlCellTypeVisible).Copy Range("b2")