注册 登录
编程论坛 Excel/VBA论坛

【求助】 把指定内容提取到新建的工作簿

yuyuyuqiuqiu 发布于 2022-05-22 11:22, 970 次点击
Sub 地质()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.Activate
Sheets("百合地质表").Activate
只有本站会员才能查看附件,请 登录

Sheets("百合地质表").Range("A3:A2500").Clear
Sheets("地质明细表").Range("A5:A2500").Copy Sheets("百合地质表").Range("A3")
Dim i, j, str, arr1, arr2, sht As Worksheet, wb   As Workbook
j = 3
arr1 = Sheets("百合地质表").Range("b1:r2")
For i = 4 To 2500
 If Cells(i, 2) <> 0 Then
  If Cells(i, 2) = 1 Then
    arr2 = ThisWorkbook.Sheets("百合地质表").Range(Cells(j, 2), Cells(i - 1, 12))
    str = ThisWorkbook.Sheets("百合地质表").Cells(i, 1)
    sFileName = ThisWorkbook.Path & "\" & str & "地质.CSV"  
    Set wb = Workbooks.Add
    Set sht = wb.Worksheets(1)
      arr1.Copy sht.Range("A1")
      arr2.Copy sht.Range("A3")
     wb.SaveAs sFileName
     wb.Close
     j = i
  End If
  End If
  Next  
 Application.DisplayAlerts = True
 Application.ScreenUpdating = True  
End Sub


想提取每一个编号对应的B:R行数据存到新的工作簿中,但提示 要求对象错误,请问如何修改

2 回复
#2
yuyuyuqiuqiu2022-05-22 11:24
只有本站会员才能查看附件,请 登录


excle文件在此
#3
厨师王德榜2022-05-25 16:20
      arr1.Copy sht.Range("A1") 这一句不对,一般把数组内容展开到表格,可以这样用:
      sht.Range("A1").Resize(行数, 列数) = arr1
1