我正在寻找一个数据循环并将某些单元格从一个工作表复制到另一个工作表。使用“longhand”我可以得到以下工作:
Sub Update()
Dim Template As Worksheet: Set Template = Worksheets("ImportTemplate")
Dim Master As Worksheet: Set Master = Worksheets("Master")
Dim a As Long, x As Long
With Master
For a = 2 To .Range("A" & Rows.Count).End(xlUp).Row
Select Case .Range("A" & a).Value
Case "S"
x = Template.Range("A" & Rows.Count).End(xlUp).Row + 1
Template.Range("A" & x).Value = .Range("E" & a).Value 'Site Details
Template.Range("B" & x).Value = .Range("AO" & a).Value 'Meter Details
Case "M"
Case "C"
Case Else
End Select
Next a
.Select
End With
End Sub
有没有“更好”的方法呢?将会有更多的单元要更新,因此它不仅限于显示的例子
答案 0 :(得分:0)
你可以包括
' at the start
Dim priorCalculationSetting as Long
Application.ScreenUpdating = False
priorCalc = Application.Calculation
Application.Calculation = xlCalculationManual
...your code here...
' at the end
Application.ScreenUpdating = True
Application.Calculation = priorCalculationSetting