我希望我能解释清楚。我的代码有困难,应该使用什么代码。 我有一个大数据,需要首先进行过滤。并且范围不一致。
在过滤数据之后,我必须复制第二行(这不是复制列名),直到最后一行空白为止。
我尝试了这段代码,但是没有用
Sheets("Big5").Select
Range("P1").Select
Dim testlrow As Long
testlrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Dim rngBIGcode As Range
Set rngBIGcodeM = Range(Cells(ActiveCell.Row + 1, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column))
rngBIGcodeM.SpecialCells(xlCellTypeVisible).Cells(1).Select
Range(Selection, Selection.End(xlDown) & testlrow).Select
我必须从P1复制第二行,直到最后一行。
答案 0 :(得分:0)
从使用Select
和ActiveCell
开始,您的代码存在一些问题。您还声明了范围,然后使用与Set
不同的名称。确保正确声明变量的一种方法是在Option Explicit
上方键入Sub
。然后它将验证您的变量。通过使用单元格前面的工作表变量,确保您的对象定义正确。这是您代码的工作方式:
Sub Test ()
Dim ws As Worksheet
Dim testlrow As Long
Dim rngBIGcodeM as Range
Set ws = Sheets("Big5")
testlrow = ws.Cells(Rows.Count, "P").End(xlUp).Row
Set rngBIGcodeM = ws.Range(ws.Cells(2, "P"), ws.Cells(testlrow, "P"))
rngBIGcodeM.SpecialCells(xlCellTypeVisible).Copy 'Enter Destination Here
Application.CutCopyMode = False
End Sub