我正在尝试将文件拆分为多组行。我希望它大约每2000行中断,但如果电子邮件地址(在AD列中)是最后一行和下一行之间的公共值,则在拆分之前获取具有相同值的所有行。
到目前为止,我有以下内容:
Sub Chunkify_Data()
Dim inputFile As String, inputWb As Workbook
Dim lastRow As Long, srow As Long, erow As Long
Dim newFile As Workbook
Dim etext As String, netext As String
With ActiveWorkbook.Worksheets(1)
lastRow = .Cells(Rows.Count, "A").End(xlUp).row
Set newFile = Workbooks.Add
srow = 1805
While erow < lastRow
erow = srow + 1999
If (erow > lastRow) Then
erow = lastRow
Else
etext = ActiveSheet.Cells(erow, 30).Value
netext = ActiveSheet.Cells(erow + 1, 30).Value
'Don't split up emails
While (StrComp(etext, netext, vbTextCompare) = 0)
erow = erow + 1
netext = ActiveSheet.Cells(erow + 1, 30).Value
Wend
End If
.Rows(1).EntireRow.Copy newFile.Worksheets(1).Range("A1")
.Rows(srow & ":" & erow).EntireRow.Copy newFile.Worksheets(1).Range("A2")
'Save in same folder as input workbook with .xlsx
newFile.SaveAs Filename:=srow & "-" & erow & ".xlsx", CreateBackup:=False
srow = erow + 1
Wend
End With
newFile.Close saveChanges:=False
End Sub
第二个netext =行失败,出现“运行时错误'1004':应用程序定义或对象定义错误”。我无法理解为什么。有什么想法吗?