因此,我正在处理将从一个工作表复制到另一个工作表的代码,以便复制到的工作表具有数据所需的确切行数,而不是更多。问题是,代码从40行到达第14行并停止。我不确定导致问题的原因。 " i"变量和"结束"变量在宏的末尾是14。我正在复制的Excel电子表格的列A由1到40的数字组成,一个单元格间隔在18到19之间,以及30和31之间。
Option Explicit
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
Dim c As Range
Dim firstAddress As String
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
firstAddress = c.Address
Do
ReDim copy(i)
copy(i - 1) = c.Value
i = i + 1
ending = i
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
i = 1
If Not i = ending Then
Do Until i = ending
Worksheets("Test Bed").Range("A" & 23 + i).Value = Worksheets("Raw Data").Range("A" & 15 + i).Value
i = i + 1
Loop
End If
End Sub