EXCEL 请教关于非当前表的操作(VBA)

来源:百度知道 编辑:UC知道 时间:2024/06/11 03:10:34
请教关于非当前表的操作
With Sheets("Skill Map")
arr = .Range("B4:AU" & .Range("B65536").End(xlUp).Row)
.Range("B4:D4").Copy Range("A1")
.Range("E4:AU4").Copy Range("J1")
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
Set d(arr(i, 1) & arr(i, 2) & arr(i, 3)) = .Cells(i + 3, 5).Resize(1, 43)
Next
End With

With Sheets("Course Map")
arr = .Range("B2:D" & .Range("B65536").End(xlUp).Row)
.Range("E1:J1").Copy Range("D1:I1")
.Range("B2:D" & .Range("B65536").End(xlUp).Row).Copy Cells(2, 1)
.Range("E2:J" & .Range("E65536").End(xlUp).Row).Copy Cells(2, 4)
End With
For i = 1 To UBound(arr)
If d.exists(arr(i,

如果要对当前文件的其他表进行操作,需要先激活,比如:
WorkSheets("Skill Map").activate

WorkSheets("Course Map").activate

楼上回答不完整,不一定先激活的
加上指定就可如

with worksheets("你要操作的表名")
.Cells.ColumnWidth = 8.38
.Cells.RowHeight = 14.25
.Columns("B:C").ColumnWidth = 10
.Columns("D:D").ColumnWidth = 16
.Columns("E:E").ColumnWidth = 26
.Range("A1:C1").Interior.ColorIndex = 55
.Range("A1:C1").Font.ColorIndex = 2
.Range("A2").AutoFilter
end with