我使用以下代码(见下文)将某些行从工作表A复制到工作表B.在A列中只有N到N的值,但在复制到工作表B后,excel会更改文档打印范围到A列XFD,因此在打印复制的工作表B时,会创建+100个空白页。我不知道导致问题的原因,我已经更改了工作表的scrollArea,但创建的打印范围仍然没有变化。是否可以使用VBA将打印范围锁定到$ A:$ N?
复制下面的代码。
Sub Samenvattend()
'
' Samenvattend Macro
'
' Sneltoets: Ctrl+Shift+S
'
If ActiveSheet.Name <> "gedetailleerde meetstaat" Then
MsgBox "Deze macro kan alleen in het werkblad 'gedetailleerde meetstaat' worden toegepast"
Else
Dim a As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("gedetailleerde meetstaat")
Set Target = ActiveWorkbook.Worksheets("samenvattende meetstaat")
j = 2 ' Start copying to row 2 in target sheet
For Each a In Source.Range("A2:A10000") ' Do 10000 rows
If a <> "" Then
Source.Rows(a.Row).Copy Target.Rows(j)
Target.Rows(j).Value = Source.Rows(a.Row).Value
Target.Cells(j, 13).FormulaR1C1 = "=RC[-4]*RC[-1]"
j = j + 1
End If
Next a
End If
End Sub
谢谢:)