[英]Excel VBA Worksheet loop - How to move through n worksheets
Here is a simple loop that is copying a range to another location on the same worksheet. 这是一个将范围复制到同一工作表上另一个位置的简单循环。 This also needs to loop through all the remaining worksheets and perform the same copy paste values.
这也需要遍历所有剩余的工作表并执行相同的复制粘贴值。 My use of variable "Dim ws" in the loop is suspect.
我在循环中使用变量“ Dim ws”令人怀疑。
Sub UpdateSPCData()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Select Case UCase(wsLoop)
Case "Data - MOAQ", "Report" 'Do nothing
Case Else
Range("H2:H5").Copy
Range("I2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Select
Next ws
End Sub
I think you need this. 我想你需要这个。 Also, if checking upper case names you must make sure you are comparing with upper case text.
另外,如果检查大写字母名称,则必须确保与大写字母文字进行比较。
Sub UpdateSPCData()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Select Case UCase(ws.Name)
Case "DATA - MOAQ", "REPORT" 'Do nothing
Case Else
ws.Range("H2:H5").Copy
ws.Range("I2").PasteSpecial Paste:=xlPasteValues
End Select
Next ws
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.