我有一个10k +行Excel文件,其结构如下:(在A栏中):“城市名称是:”后跟几行开头
“......的贡献”接着是
不感兴趣的线......其次是
“案例结束”......并重复。
我需要提取以“城市名称”开头的行和“城市名称”后面的“贡献来自”行,并将每组行粘贴到单独的工作表中。你能帮我吗?永远感谢。
答案 0 :(得分:0)
我不知道,我理解你的问题。
Sub transData()
Dim vDB, vR()
Dim i As Long, n As Long
vDB = ActiveSheet.UsedRange
For i = 1 To UBound(vDB, 1)
If Left(vDB(i, 1), 4) = "Name" Then
n = n + 1
ReDim Preserve vR(1 To n)
End If
vR(n) = vR(n) & " " & vDB(i, 1)
Next i
Sheets.Add
Range("a1").Resize(n) = WorksheetFunction.Transpose(vR)
End Sub
或者,
Sub transData()
Dim vDB, vR()
Dim i As Long, n As Long
vDB = ActiveSheet.UsedRange
For i = 1 To UBound(vDB, 1)
If Left(vDB(i, 1), 4) = "Name" Then
n = n + 1
ReDim Preserve vR(1 To n)
End If
If Left(vDB(i, 1), 4) = "Name" Or Left(vDB(i, 1), 12) = "contribution" Then
vR(n) = vR(n) & " " & vDB(i, 1)
End If
Next i
Sheets.Add
Range("a1").Resize(n) = WorksheetFunction.Transpose(vR)
End Sub