【发布时间】:2019-10-01 19:18:31
【问题描述】:
我想从我的 Dump 工作表中获取数据,检查 A 列中的值是否存在于我的 RA 工作表的 A 列中。如果是,则复制所有整行并粘贴到 RA 选项卡中,如果没有将数据发布到 Acq 选项卡中。我目前让它工作,但它需要很长时间,我觉得必须有一种方法可以用范围来做到这一点,但“j.row j.column”部分让我很难过。有什么建议吗?
Private Sub CommandButton1_Click()
Dim Dump As Worksheet
Dim RA As Worksheet
Dim Acq As Worksheet
Dim i As Integer
Set Dump = Worksheets("Dump")
Set RA = Worksheets("Retained Revenue Achieved")
Set Acq = Worksheets("New Business Revenue Achieved")
k = Dump.Cells(Rows.Count, "A").End(xlUp).Row + 1
'check through each row in the Dump'
For i = 5 To k
findvalue = Dump.Cells(i, 1).Value
Set J = RA.Range("A:A").Find(findvalue)
'if the customer id exists in RA then copy and paste the row from Dump to RA'
If Not J Is Nothing Then
RA.Cells(J.Row, J.Column).Offset(0, 1).Value = Dump.Cells(i, 2).Value
RA.Cells(J.Row, J.Column).Offset(0, 2).Value = Dump.Cells(i, 3).Value
RA.Cells(J.Row, J.Column).Offset(0, 3).Value = Dump.Cells(i, 4).Value
RA.Cells(J.Row, J.Column).Offset(0, 4).Value = Dump.Cells(i, 5).Value
RA.Cells(J.Row, J.Column).Offset(0, 5).Value = Dump.Cells(i, 6).Value
RA.Cells(J.Row, J.Column).Offset(0, 6).Value = Dump.Cells(i, 7).Value
RA.Cells(J.Row, J.Column).Offset(0, 7).Value = Dump.Cells(i, 8).Value
RA.Cells(J.Row, J.Column).Offset(0, 8).Value = Dump.Cells(i, 9).Value
RA.Cells(J.Row, J.Column).Offset(0, 9).Value = Dump.Cells(i, 10).Value
RA.Cells(J.Row, J.Column).Offset(0, 10).Value = Dump.Cells(i, 11).Value
RA.Cells(J.Row, J.Column).Offset(0, 11).Value = Dump.Cells(i, 12).Value
RA.Cells(J.Row, J.Column).Offset(0, 12).Value = Dump.Cells(i, 13).Value
RA.Cells(J.Row, J.Column).Offset(0, 13).Value = Dump.Cells(i, 14).Value
RA.Cells(J.Row, J.Column).Offset(0, 14).Value = Dump.Cells(i, 15).Value
RA.Cells(J.Row, J.Column).Offset(0, 15).Value = Dump.Cells(i, 16).Value
RA.Cells(J.Row, J.Column).Offset(0, 16).Value = Dump.Cells(i, 17).Value
RA.Cells(J.Row, J.Column).Offset(0, 17).Value = Dump.Cells(i, 18).Value
RA.Cells(J.Row, J.Column).Offset(0, 18).Value = Dump.Cells(i, 19).Value
RA.Cells(J.Row, J.Column).Offset(0, 19).Value = Dump.Cells(i, 20).Value
RA.Cells(J.Row, J.Column).Offset(0, 20).Value = Dump.Cells(i, 21).Value
RA.Cells(J.Row, J.Column).Offset(0, 21).Value = Dump.Cells(i, 22).Value
RA.Cells(J.Row, J.Column).Offset(0, 22).Value = Dump.Cells(i, 23).Value
RA.Cells(J.Row, J.Column).Offset(0, 23).Value = Dump.Cells(i, 24).Value
RA.Cells(J.Row, J.Column).Offset(0, 24).Value = Dump.Cells(i, 25).Value
RA.Cells(J.Row, J.Column).Offset(0, 25).Value = Dump.Cells(i, 26).Value
RA.Cells(J.Row, J.Column).Offset(0, 26).Value = Dump.Cells(i, 27).Value
RA.Cells(J.Row, J.Column).Offset(0, 27).Value = Dump.Cells(i, 28).Value
RA.Cells(J.Row, J.Column).Offset(0, 28).Value = Dump.Cells(i, 29).Value
RA.Cells(J.Row, J.Column).Offset(0, 29).Value = Dump.Cells(i, 30).Value
RA.Cells(J.Row, J.Column).Offset(0, 30).Value = Dump.Cells(i, 31).Value
RA.Cells(J.Row, J.Column).Offset(0, 31).Value = Dump.Cells(i, 32).Value
RA.Cells(J.Row, J.Column).Offset(0, 32).Value = Dump.Cells(i, 33).Value
RA.Cells(J.Row, J.Column).Offset(0, 33).Value = Dump.Cells(i, 34).Value
RA.Cells(J.Row, J.Column).Offset(0, 34).Value = Dump.Cells(i, 35).Value
RA.Cells(J.Row, J.Column).Offset(0, 35).Value = Dump.Cells(i, 36).Value
RA.Cells(J.Row, J.Column).Offset(0, 36).Value = Dump.Cells(i, 37).Value
RA.Cells(J.Row, J.Column).Offset(0, 37).Value = Dump.Cells(i, 38).Value
RA.Cells(J.Row, J.Column).Offset(0, 38).Value = Dump.Cells(i, 39).Value
RA.Cells(J.Row, J.Column).Offset(0, 39).Value = Dump.Cells(i, 40).Value
RA.Cells(J.Row, J.Column).Offset(0, 40).Value = Dump.Cells(i, 41).Value
RA.Cells(J.Row, J.Column).Offset(0, 41).Value = Dump.Cells(i, 42).Value
RA.Cells(J.Row, J.Column).Offset(0, 42).Value = Dump.Cells(i, 43).Value
RA.Cells(J.Row, J.Column).Offset(0, 43).Value = Dump.Cells(i, 44).Value
RA.Cells(J.Row, J.Column).Offset(0, 44).Value = Dump.Cells(i, 45).Value
RA.Cells(J.Row, J.Column).Offset(0, 45).Value = Dump.Cells(i, 46).Value
RA.Cells(J.Row, J.Column).Offset(0, 46).Value = Dump.Cells(i, 47).Value
RA.Cells(J.Row, J.Column).Offset(0, 47).Value = Dump.Cells(i, 48).Value
RA.Cells(J.Row, J.Column).Offset(0, 48).Value = Dump.Cells(i, 49).Value
RA.Cells(J.Row, J.Column).Offset(0, 49).Value = Dump.Cells(i, 50).Value
RA.Cells(J.Row, J.Column).Offset(0, 50).Value = Dump.Cells(i, 51).Value
RA.Cells(J.Row, J.Column).Offset(0, 51).Value = Dump.Cells(i, 52).Value
RA.Cells(J.Row, J.Column).Offset(0, 52).Value = Dump.Cells(i, 53).Value
RA.Cells(J.Row, J.Column).Offset(0, 53).Value = Dump.Cells(i, 54).Value
'if the customer id does not exist in RA, then look for it in Acq'
Else
Set M = Acq.Range("A:A").Find(findvalue)
'if the customer id exists in Acq then copy and paste the customer id from dump to Acq'
If Not M Is Nothing Then
Acq.Cells(M.Row, M.Column).Offset(0, 1).Value = Dump.Cells(i, 2).Value
Acq.Cells(M.Row, M.Column).Offset(0, 2).Value = Dump.Cells(i, 3).Value
Acq.Cells(M.Row, M.Column).Offset(0, 3).Value = Dump.Cells(i, 4).Value
Acq.Cells(M.Row, M.Column).Offset(0, 4).Value = Dump.Cells(i, 5).Value
Acq.Cells(M.Row, M.Column).Offset(0, 5).Value = Dump.Cells(i, 6).Value
Acq.Cells(M.Row, M.Column).Offset(0, 6).Value = Dump.Cells(i, 7).Value
Acq.Cells(M.Row, M.Column).Offset(0, 7).Value = Dump.Cells(i, 8).Value
Acq.Cells(M.Row, M.Column).Offset(0, 8).Value = Dump.Cells(i, 9).Value
Acq.Cells(M.Row, M.Column).Offset(0, 9).Value = Dump.Cells(i, 10).Value
Acq.Cells(M.Row, M.Column).Offset(0, 10).Value = Dump.Cells(i, 11).Value
Acq.Cells(M.Row, M.Column).Offset(0, 11).Value = Dump.Cells(i, 12).Value
Acq.Cells(M.Row, M.Column).Offset(0, 12).Value = Dump.Cells(i, 13).Value
Acq.Cells(M.Row, M.Column).Offset(0, 13).Value = Dump.Cells(i, 14).Value
Acq.Cells(M.Row, M.Column).Offset(0, 14).Value = Dump.Cells(i, 15).Value
Acq.Cells(M.Row, M.Column).Offset(0, 15).Value = Dump.Cells(i, 16).Value
Acq.Cells(M.Row, M.Column).Offset(0, 16).Value = Dump.Cells(i, 17).Value
Acq.Cells(M.Row, M.Column).Offset(0, 17).Value = Dump.Cells(i, 18).Value
Acq.Cells(M.Row, M.Column).Offset(0, 18).Value = Dump.Cells(i, 19).Value
Acq.Cells(M.Row, M.Column).Offset(0, 19).Value = Dump.Cells(i, 20).Value
Acq.Cells(M.Row, M.Column).Offset(0, 20).Value = Dump.Cells(i, 21).Value
Acq.Cells(M.Row, M.Column).Offset(0, 21).Value = Dump.Cells(i, 22).Value
Acq.Cells(M.Row, M.Column).Offset(0, 22).Value = Dump.Cells(i, 23).Value
Acq.Cells(M.Row, M.Column).Offset(0, 23).Value = Dump.Cells(i, 24).Value
Acq.Cells(M.Row, M.Column).Offset(0, 24).Value = Dump.Cells(i, 25).Value
Acq.Cells(M.Row, M.Column).Offset(0, 25).Value = Dump.Cells(i, 26).Value
Acq.Cells(M.Row, M.Column).Offset(0, 26).Value = Dump.Cells(i, 27).Value
Acq.Cells(M.Row, M.Column).Offset(0, 27).Value = Dump.Cells(i, 28).Value
Acq.Cells(M.Row, M.Column).Offset(0, 28).Value = Dump.Cells(i, 29).Value
Acq.Cells(M.Row, M.Column).Offset(0, 29).Value = Dump.Cells(i, 30).Value
Acq.Cells(M.Row, M.Column).Offset(0, 30).Value = Dump.Cells(i, 31).Value
Acq.Cells(M.Row, M.Column).Offset(0, 31).Value = Dump.Cells(i, 32).Value
Acq.Cells(M.Row, M.Column).Offset(0, 32).Value = Dump.Cells(i, 33).Value
Acq.Cells(M.Row, M.Column).Offset(0, 33).Value = Dump.Cells(i, 34).Value
Acq.Cells(M.Row, M.Column).Offset(0, 34).Value = Dump.Cells(i, 35).Value
Acq.Cells(M.Row, M.Column).Offset(0, 35).Value = Dump.Cells(i, 36).Value
Acq.Cells(M.Row, M.Column).Offset(0, 36).Value = Dump.Cells(i, 37).Value
Acq.Cells(M.Row, M.Column).Offset(0, 37).Value = Dump.Cells(i, 38).Value
Acq.Cells(M.Row, M.Column).Offset(0, 38).Value = Dump.Cells(i, 39).Value
Acq.Cells(M.Row, M.Column).Offset(0, 39).Value = Dump.Cells(i, 40).Value
Acq.Cells(M.Row, M.Column).Offset(0, 40).Value = Dump.Cells(i, 41).Value
Acq.Cells(M.Row, M.Column).Offset(0, 41).Value = Dump.Cells(i, 42).Value
Acq.Cells(M.Row, M.Column).Offset(0, 42).Value = Dump.Cells(i, 43).Value
Acq.Cells(M.Row, M.Column).Offset(0, 43).Value = Dump.Cells(i, 44).Value
Acq.Cells(M.Row, M.Column).Offset(0, 44).Value = Dump.Cells(i, 45).Value
Acq.Cells(M.Row, M.Column).Offset(0, 45).Value = Dump.Cells(i, 46).Value
Acq.Cells(M.Row, M.Column).Offset(0, 46).Value = Dump.Cells(i, 47).Value
Acq.Cells(M.Row, M.Column).Offset(0, 47).Value = Dump.Cells(i, 48).Value
Acq.Cells(M.Row, M.Column).Offset(0, 48).Value = Dump.Cells(i, 49).Value
Acq.Cells(M.Row, M.Column).Offset(0, 49).Value = Dump.Cells(i, 50).Value
Acq.Cells(M.Row, M.Column).Offset(0, 50).Value = Dump.Cells(i, 51).Value
Acq.Cells(M.Row, M.Column).Offset(0, 51).Value = Dump.Cells(i, 52).Value
Acq.Cells(M.Row, M.Column).Offset(0, 52).Value = Dump.Cells(i, 53).Value
Acq.Cells(M.Row, M.Column).Offset(0, 53).Value = Dump.Cells(i, 54).Value
'if the customer id doesnt exist in RA or Acq, then add it to the bottom of the list in Acq'
Else
r = Acq.Cells(Rows.Count, "A").End(xlUp).Row + 1
Acq.Cells(r, 1).Value = Dump.Cells(i, 1).Value
Acq.Cells(r, 2).Value = Dump.Cells(i, 2).Value
Acq.Cells(r, 3).Value = Dump.Cells(i, 3).Value
Acq.Cells(r, 4).Value = Dump.Cells(i, 4).Value
Acq.Cells(r, 5).Value = Dump.Cells(i, 5).Value
Acq.Cells(r, 6).Value = Dump.Cells(i, 6).Value
Acq.Cells(r, 7).Value = Dump.Cells(i, 7).Value
Acq.Cells(r, 8).Value = Dump.Cells(i, 8).Value
Acq.Cells(r, 9).Value = Dump.Cells(i, 9).Value
Acq.Cells(r, 10).Value = Dump.Cells(i, 10).Value
Acq.Cells(r, 11).Value = Dump.Cells(i, 11).Value
Acq.Cells(r, 12).Value = Dump.Cells(i, 12).Value
Acq.Cells(r, 13).Value = Dump.Cells(i, 13).Value
Acq.Cells(r, 14).Value = Dump.Cells(i, 14).Value
Acq.Cells(r, 15).Value = Dump.Cells(i, 15).Value
Acq.Cells(r, 16).Value = Dump.Cells(i, 16).Value
Acq.Cells(r, 17).Value = Dump.Cells(i, 17).Value
Acq.Cells(r, 18).Value = Dump.Cells(i, 18).Value
Acq.Cells(r, 19).Value = Dump.Cells(i, 19).Value
Acq.Cells(r, 20).Value = Dump.Cells(i, 20).Value
Acq.Cells(r, 21).Value = Dump.Cells(i, 21).Value
Acq.Cells(r, 22).Value = Dump.Cells(i, 22).Value
Acq.Cells(r, 23).Value = Dump.Cells(i, 23).Value
Acq.Cells(r, 24).Value = Dump.Cells(i, 24).Value
Acq.Cells(r, 25).Value = Dump.Cells(i, 25).Value
Acq.Cells(r, 26).Value = Dump.Cells(i, 26).Value
Acq.Cells(r, 27).Value = Dump.Cells(i, 27).Value
Acq.Cells(r, 28).Value = Dump.Cells(i, 28).Value
Acq.Cells(r, 29).Value = Dump.Cells(i, 29).Value
Acq.Cells(r, 30).Value = Dump.Cells(i, 30).Value
Acq.Cells(r, 31).Value = Dump.Cells(i, 31).Value
Acq.Cells(r, 32).Value = Dump.Cells(i, 32).Value
Acq.Cells(r, 33).Value = Dump.Cells(i, 33).Value
Acq.Cells(r, 34).Value = Dump.Cells(i, 34).Value
Acq.Cells(r, 35).Value = Dump.Cells(i, 35).Value
Acq.Cells(r, 36).Value = Dump.Cells(i, 36).Value
Acq.Cells(r, 37).Value = Dump.Cells(i, 37).Value
Acq.Cells(r, 38).Value = Dump.Cells(i, 38).Value
Acq.Cells(r, 39).Value = Dump.Cells(i, 39).Value
Acq.Cells(r, 40).Value = Dump.Cells(i, 40).Value
Acq.Cells(r, 41).Value = Dump.Cells(i, 41).Value
Acq.Cells(r, 42).Value = Dump.Cells(i, 42).Value
Acq.Cells(r, 43).Value = Dump.Cells(i, 43).Value
Acq.Cells(r, 44).Value = Dump.Cells(i, 44).Value
Acq.Cells(r, 45).Value = Dump.Cells(i, 45).Value
Acq.Cells(r, 46).Value = Dump.Cells(i, 46).Value
Acq.Cells(r, 47).Value = Dump.Cells(i, 47).Value
Acq.Cells(r, 48).Value = Dump.Cells(i, 48).Value
Acq.Cells(r, 49).Value = Dump.Cells(i, 49).Value
Acq.Cells(r, 50).Value = Dump.Cells(i, 50).Value
Acq.Cells(r, 51).Value = Dump.Cells(i, 51).Value
Acq.Cells(r, 52).Value = Dump.Cells(i, 52).Value
Acq.Cells(r, 53).Value = Dump.Cells(i, 53).Value
Acq.Cells(r, 54).Value = Dump.Cells(i, 54).Value
End If
End If
Next i
End Sub
【问题讨论】:
-
j.Offset(0, 1).Resize(1,53).Value = Dump.Cells(i, 2).resize(1,53).Value和M.Offset(0, 1).Resize(1,53).Value = Dump.Cells(i, 2).resize(1,53).Value不需要逐个单元格。全部在线完成。