我在Sheet2上有一系列数据将它链接到Sheet1(Sheet1由Sheet2格式化并使用=if(Sheet2$x$x="","",Sheet2$x$x)
链接;这样,任何放入Sheet2范围C13:G62的数据都显示在Sheet1范围C13中:G62。代码的开头部分用于将指定范围内的数据移动到BATCH文件Sheet3,并查找最后一行粘贴Sheet1中的值而不复制公式。这样做是为了我可以删除数据Sheet2擦除Sheet1干净但仍然在一个Sheet3上拥有所有备份数据。
无论如何,问题在于我试图操作代码将Sheet1上的所有内容(到DUPLICATE SHEET1)复制到工作簿末尾的另一个工作表:
Sheets(Sheet1).Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = _
InputBox("Name of the New WorkSheet")
这让我可以说出很棒的表格。但是,通过创建多个代码变体,它不会将RANGE中的DATA移动到新创建的Sheet4(没有数据)。在代码的一次迭代中,我能够让Sheet1复制并在工作簿的末尾创建Sheet4,但是没有数据在范围内,但是光标位于单元格C13中,这是粘贴值的起点,当我左键单击该单元格中的鼠标以“#34;粘贴值"它会粘贴我试图粘贴的值。但是,无论采用哪种方式重新排列代码,数据都会被复制,但永远不会粘贴到Sheet4范围。
在这里,我发布了一个代码的变体,它仍然不会将值限制在第4页(新创建的页面),但仍然复制到BATCH文件。我在这里错过了什么?
Dim s1Sheet As Worksheet
Dim s2Sheet As Worksheet
Dim source As String
Dim target As String
Dim rngSource As Range
Dim rngTargetStart As Range
source = "Invoice"
target = "TOTAL_INVOICE"
Application.EnableCancelKey = xlDisabled
Set s1Sheet = Sheets(source)
Set s2Sheet = Sheets(target)
Set rngSource = s1Sheet.Range("C13:G62")
Set rngTargetStart = s2Sheet.Range("C" & Rows.Count).End(xlUp).Offset(1)
'Set rngTargetFinish = ws1.Range("C" & Rows.Count).End(xlUp).Offset(1)
rngTargetStart.Resize(rngSource.Rows.Count, rngSource.Columns.Count).Value = rngSource.Value
'rngTargetFinish.Resize(rngSource.Rows.Count, rngSource.Columns.Count).Value = rngSource.Value
'Set target = Sheets("Sheet4").Range("B13:G63")
copy_non_formulas source:=rngSource, target:=rngTargetStart
' copy_non_formulas source:=Range("B13:G63"), target:=Range("B70:G109") Unhighlight
' copy_non_formulas source:=Range("B13:G63"), target:=Range("B13:G63") Unhighlight
'===Copies Sheet to End of WorkBook & Pastes Values======
Sheets(source).Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = _
InputBox("Name of the New WorkSheet")
Range("C13:G62").ClearContents
Dim rng As Range
Set rng = ActiveSheet.Range("C13:G62")
rng.ClearContents
Dim s3Sheet As Worksheet
Dim rngTargetStart2 As Range
Set s3Sheet = Sheets(Sheets.Count)
Set rngTargetStart2 = s3Sheet.Range("C" & Rows.Count).End(xlUp).Offset(1)
rngTargetStart2.Resize(rngSource.Rows.Count, rngSource.Columns.Count).Value = rngSource.Value
copy_non_formulas2 source:=rngSource, target2:=rngTargetStart2
copy_non_formulas2 source:=Range("C13:G62"), target2:=Range("C13:G62")
这是一个综合公共子
copy_non_formulas(source As Range, target As Range)
Dim i As Long
Dim j As Long
Dim c As Range
For i = 1 To source.Rows.Count
For j = 1 To source.Columns.Count
Set c = source(RowIndex:=i, ColumnIndex:=j)
If Left(c.Formula, 1) <> "=" Then
target(RowIndex:=i, ColumnIndex:=j).Value = c.Value
End If
Next j
Next i
第二次移动的另一个公共子项
copy_non_formulas2(source As Range, target2 As Range)
Dim x As Long
Dim y As Long
Dim d As Range
For x = 1 To source.Rows.Count
For y = 1 To source.Columns.Count
Set d = source(RowIndex:=x, ColumnIndex:=y)
If Left(d.Formula, 1) <> "=" Then
target2(RowIndex:=x, ColumnIndex:=y).Value = d.Value
End If
Next y
Next x