简体   繁体   English

使用循环将多个工作表复制到同一工作簿中的多个不同工作表中

[英]Using loop for copying several sheets into several different sheets in same workbook

I have this code. 我有这个代码。 Can I copy all the sheets using one single code using a loop? 我可以使用一个循环使用一个代码来复制所有工作表吗?

Sub clearLKP_68()
Sheet7.Cells.Clear
End Sub


Sub copyFromRel68ToLKP_68()
Sheets("Rel 6.8").Columns("A:R").copy Sheets("LKP_68").Range("A1")
End Sub

Sub clearLKP_69()
Sheet8.Cells.Clear
End Sub


Sub copyFromRel69ToLKP_69()
Sheets("Rel 6.9").Columns("A:R").copy Sheets("LKP_69").Range("A1")
End Sub

Sub clearLKP_70()
Sheet9.Cells.Clear
End Sub


Sub copyFromRel70ToLKP_70()
Sheets("Rel 7.0").Columns("A:R").copy Sheets("LKP_70").Range("A1")
End Sub

Does this work for you? 这对您有用吗? Feel free to ask if there's anything that's unclear. 随意询问是否有任何不清楚的地方。

Option Explicit

Sub test()
  Dim separator As String
  Dim i As Long

  separator = Application.DecimalSeparator
  Application.DecimalSeparator = "."
  For i = 68 To 70
    Worksheets("LKP_" & CStr(i)).Cells.Clear
    Worksheets("Rel " & Format(i / 10#, "0.0")).Columns("A:R").Copy Destination:=Worksheets("LKP_" & CStr(i)).Range("A1")
  Next i
  Application.DecimalSeparator = separator
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM