为什么twb单元格(i,7)的值未显示在extwb(pasterowIndex,1)中?
您能做到吗
twb.Sheets(1).Activate
Cells(i, 7).Select
Selection.Copy
extwb.Sheets(8).Activate
Cells(pasterowIndex, 1).Select
ActiveSheet.Paste
代码有点简单,因为我有很多要复制的价值?
Sub historical()
Dim twb As Workbook
Dim extwb As Workbook
Dim extwb3 As Worksheet
Dim i As Long
Dim pasterowIndex As Long
pasterowIndex = 2
Set twb = Workbooks.Open("C:\Users\faisal.abraham\Documents\Travel\PUPD.xlsx")
Set extwb = Workbooks.Open("C:\Users\faisal.abraham\Documents\Travel\PIRD.xlsx")
With twb.Sheets("Actuary_Travel_Voucher_Engineer")
For i = 8 To Cells(Rows.Count, 1).End(xlUp).Row
If twb.Cells(i, 23).Value = "PERMATA HIJAU " And Cells(i, 28).Value = "PAID" Then
twb.Sheets(1).Activate
Cells(i, 7).Select
Selection.Copy
extwb.Sheets(8).Activate
Cells(pasterowIndex, 1).Select
ActiveSheet.Paste
pasterowIndex = pasterowIndex + 1
End If
Next i
pasterowIndex = 2
End With
End Sub
答案 0 :(得分:1)
此代码
twb.Sheets(1).Activate
Cells(i, 7).Select
Selection.Copy
extwb.Sheets(8).Activate
Cells(pasterowIndex, 1).Select
ActiveSheet.Paste
可以替换为
twb.Sheets(1).cells(i,7).copy extwb.sheets(8).cells(pasteindex,1)
无法解决其他问题,但至少可以减轻代码的痛苦