Board logo

標題: [發問] vba 資料比對 [打印本頁]

作者: markbaseball    時間: 2016-4-12 10:30     標題: vba 資料比對

各位大大:
                 我現在有兩個工作表,我首先需要比對workbook1 和workbook2的 id是否相同,如果id相同再比對日期,日期也一致的話就把workbook 1的值 貼到workbook2 。
        Workbook1                                                      workbook2
ID         日期               MV                                 ID         日期               MV
1      2000/1/1          50                                    1         2000/1/2
1      2000/1/2          52                                    2          2000/1/6
1      2000/1/3          54                                    3          2000/1/7
1      2000/1/4          53                                   
2     2000/1/5            60
2      2000/1/6           61
3     2000/1/7            52


Sub marketvalue()
Dim i, j As Integer
Dim tt, cc As Date
    Set tbill = Workbooks("mv").Sheets("data")
    Set aaa = Workbooks("財務資料").Sheets("sheet2")
      For i = 2 To 1048576
      For j = 2 To 1148
       Let BCODE = tbill.Cells(i, 1)
       tt = tbill.Range("B" & i).Value
       cc = aaa.Range("A" & j).Value
        With aaa.Range("E:E")
            Set c = Cells.Find(what:=BCODE, After:=ActiveCell, LookIn:= _
                               xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, MatchCase:=False).Activate

            If Not c Is Nothing Then
                       With aaa.Range("A:A")
                            Set dd = Cells.Find(what:=tt, After:=ActiveCell, LookIn:= _
                               xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                               SearchDirection:=xlNext, MatchCase:=False).Activate
                                     If Not dd Is Nothing Then
                                        tbill.Cells(i, 5).Copy Destination:=aaa.Cells(j, 15)
                                     End If
                       End With
            End If
         End With
     Next j
     Next i
End Sub

但是這行卻出現沒有設定物件變數或with區塊變數, 請問該怎麼修改??
作者: VBALearner    時間: 2016-8-4 16:12

回復 1# markbaseball

首先 你的某一行程式碼打錯了(嗎?!)
Let BCODE = tbill.Cells(i, 1)
Let要改Set吧?




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)