1
我试图拿出一个粗略的数据列表,然后将其复制到预先格式化的组织形式。为此,我设置了粗略列表,以便列表中的每个项目都按顺序编号,而不管项目之间是否有空格。我试图制作的宏将采用粗略列表并将其复制到没有任何空格的表单中。忍受我,我一直在试图自学Visual Basic,所以我有的代码可能......凌乱。当前,我遇到的问题是,我得到我的溢出= 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
这样做,谢谢EEM! –
很高兴帮助你!你是否尝试用一种数据替换第一个循环,并用类似'Range.resize(ubound(array),ubound(array,2))的值替换第二个循环。value = Array'来发布整个阵列一次? – EEM