返回列表 上一主題 發帖

TEST與資料檔(材料)工作表比對

If Sheets("資料檔(材料)").Cells(myrow2, 1) = Sheets("TEST").Cells(myrow, 1)  AND  Sheets("資料檔(材料)").Cells(myrow2, 18) Then

TOP

回復 1# plyl
3.完全吻合就將資料檔("A3")貼到TEST ("B4")
這句對嗎?
是否是   完全吻合就將 "資料檔"的資料 從TEST ("B4")往下貼上
  1. Option Explicit
  2. '註:1.我有兩個工作表"TEST' "資料檔"
  3.    '2.TEST("A4:A50")與資料檔("A2:A500")做比對
  4.    '3.完全吻合就將資料檔("A3")貼到TEST ("B4")
  5. Private Sub AA_Click()
  6.     Dim myrow, myrow2, myrow3 As Integer
  7.     myrow3 = 4
  8.     For myrow = 4 To 50
  9.         For myrow2 = 2 To 5000
  10.             If Sheets("TEST").Cells(myrow, 1) = Sheets("資料檔").Cells(myrow2, 1) Then
  11.                     Sheets("TEST").Cells(myrow3, 2) = Sheets("資料檔").Cells(myrow2, 1)
  12.                     myrow3 = myrow3 + 1
  13.             End If
  14.         Next
  15.     Next
  16. End Sub
複製代碼

TOP

回復 5# plyl
Private Sub AA_Click()
    Dim myrow, myrow2, myrow3 As Integer
    myrow3 = 4
    For myrow = 4 To 50
   If Sheets("TEST").Cells(myrow, 1) = "" Then Exit For   是加在這裡嗎?
   錯了, 假如上式的myrow=10 且  Sheets("TEST").Cells(myrow, 1) = ""  會離開For myrow 的回圈
   那  myrow的 11,12,13....... 的Sheets("TEST").Cells(myrow, 1) 就比對不到了
   請改成   
   If Sheets("TEST").Cells(myrow, 1) <> "" Then      
        For myrow2 = 2 To 5000
            If Sheets("TEST").Cells(myrow, 1) = Sheets("資料檔").Cells(myrow2, 1) Then
                    Sheets("TEST").Cells(myrow3, 2) = Sheets("資料檔").Cells(myrow2, 1)
                    myrow3 = myrow3 + 1
            End If
        Next
    End If    
    Next
End Sub

TOP

回復 7# plyl
If Sheets("TEST").Cells(myrow, 1) = Sheets("資料檔(材料)").Cells(myrow2, 1) Then
如這條件成立時  請問Sheets("資料檔(材料)").Cells(myrow2, 1)是有資料的嗎?
                    'ITO RECIPE
              Sheets("TEST").Cells(myrow3, 41) = Sheets("資料檔(材料)").Cells(myrow2, 32)
                   'ITES 可RUN 01 OR 02
                Sheets("TEST").Cells(myrow3, 64) = Sheets("資料檔(材料)").Cells(myrow2, 33)
                    myrow3 = myrow3 + 1
             If Sheets("TEST").Cells(myrow, 1) = "" Then Exit For     {我是放在這裡}      
             如 有資料 上式永不會成立的
End If

TOP

回復 9# plyl
方法2
If Sheets("TEST").Cells(myrow, 1) = Sheets("資料檔(材料)").Cells(myrow2, 1) Then
              'ITO RECIPE
              If Sheets("TEST").Cells(myrow, 1) = "" Then Exit For  '放這裡才正確              Sheets("TEST").Cells(myrow3, 41) = Sheets("資料檔(材料)").Cells(myrow2, 32)
              'ITES 可RUN 01 OR 02
              Sheets("TEST").Cells(myrow3, 64) = Sheets("資料檔(材料)").Cells(myrow2, 33)
              myrow3 = myrow3 + 1
End If

TOP

        靜思自在 : 布施如播種,以歡喜心滋潤種子,才會發芽。
返回列表 上一主題