永发信息网

excel vba 选定变化区域

答案:3  悬赏:70  手机版
解决时间 2021-11-21 01:33
  • 提问者网友:两耳就是菩提
  • 2021-11-20 04:58
excel vba 选定变化区域
最佳答案
  • 五星知识达人网友:风格不统一
  • 2021-11-20 05:15
Sub bb()
Set book1 = Workbooks("book1.xls")
Set book2 = Workbooks("book2.xls")
With book1.Sheets("sheet1")
endrow = .Range("d65535").End(xlUp).Row
For i = endrow To 1 Step -1
If Range("d" & i) <> 0 Then
erow = i
Exit For
End If
Next
'以上代码找到最后一个非零值
If d1 <> 0 Then
.Range("A1:d" & erow).Copy _
Workbooks("Book2.xls").Sheets("sheet2").Range("A1")
'book1的sheet1的A1:d?复制到book2的sheet2

book1.Sheets("sheet3").Range("A1:d" & erow).Copy _
book2.Sheets("sheet6").Range("A1")
'book1的sheet3的A1:d?复制到book2的sheet6

book1.Sheets("sheet4").Range("A1:d" & erow).Copy _
book2.Sheets("sheet7").Range("A1")
'book1的sheet4的A1:d?复制到book2的sheet7

book1.Sheets("sheet5").Range("A1:c" & erow).Copy _
book2.Sheets("sheet8").Range("A1")
'book1的sheet5的A1:C?复制到book2的sheet8

book1.Sheets("sheet8").Range("A1:d" & erow).Copy _
book2.Sheets("sheet11").Range("A1")
'book1的sheet8的A1:C?复制到book2的sheet11
End If
End With
'
End Sub
'以上代码属通用性
全部回答
  • 1楼网友:夜风逐马
  • 2021-11-20 06:50
…… For Each rg In Range("d1:d65536")
If rg = 0 Then Exit For
Next rg
If rg.Row = 1 Then Exit Sub
Range("a1:d" & (rg.Row - 1)).Copy
……
  • 2楼网友:有你哪都是故乡
  • 2021-11-20 05:46
If Range("D1") = 0 Then
'nothing
Else
Range("A1:D" & Range("D65536").End(xlUp).Row).Copy
End If
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯