|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
版主,我调试了3个多小时,买了书研究(别怕,EXCEL其实VBA很简单),翻来覆去找不到答案
在这一行sht.Rows(M & ":" & N).Select出错,代码 1004, 类RANGE 的 SELECT 方法无效
Sub HB()
Application.ScreenUpdating = False
Dim wt As Worksheet
Dim filename As String, sht As Worksheet, wb As Workbook
Dim Erow As Long, Fn As String, arr As Variant, N As Integer, M As Integer
Set wt = ThisWorkbook.Worksheets("Vessel Specifications")
filename = Dir(ThisWorkbook.Path & "\*.xlsx")
Do While filename <> ""
If filename <> ThisWorkbook.Name Then
Erow = wt.Range("A1").CurrentRegion.Rows.Count + 1
Fn = ThisWorkbook.Path & "\" & filename
Set wb = GetObject(Fn)
Set sht = wb.Worksheets(6)
N = sht.Range("A65536").End(xlUp).Row
M = N - 20
sht.Rows(M & ":" & N).Select
Selection.Copy
wt.Cells(Erow, "A").Activate
ActiveSheet.Paste
End If
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub |
|