检查值是否存在,然后复制到另一个工作表

我试图拿出一个粗略的数据列表,然后将其复制到一个预先格式化,有组织的forms。 为此,我设置了粗略列表,以便列表中的每个项目按顺序编号,而不pipe项目之间是否有空格。 我试图制作的macros将采取粗略的列表,并将其复制到没有任何空格的表单。 忍受着我,我一直在试图教自己的Visual Basic,所以我的代码可能是…凌乱。 目前,我遇到的问题是我在i = i + 1上溢出。

Sub Print_Sheet_Populate() ' ' Print_Sheet_Populate Macro ' Takes Items from Raw Data sheet and puts them in Print Sheet sheet. ' ' Dim wsS1 As Worksheet Dim wsS2 As Worksheet Dim ending As Long Dim copy() As Long Dim i As Long Set wsS1 = Sheets("Raw Data") Set wsS2 = Sheets("Print Sheet") With wsS1.Range("A:A") 'To copy the item numbers in the rough data to an array i = 1 Set c = .Find(i, LookIn:=xlValues) If Not c Is Nothing Then ReDim copy(i) copy(i - 1) = c.Value Do i = i + 1 ending = i Loop While Not c Is Nothing End If End With With wsS2.Range("A24:A324") 'To paste the data from the array to the form i = 1 If Not i = ending Then Do Worksheets("wsS2").Range("A" & i).Value = copy(i - 1) i = i + 1 Loop While Not c Is Nothing End If End With End Sub 

取自Range.Find方法(Excel) :

当search到达指定search范围的末尾时,它将环绕到范围的开始位置。 要在此环绕发生时停止search,请保存find的第一个单元的地址,然后根据此保存的地址testing每个连续的发现单元地址。