返回列表 上一主題 發帖

[發問] 資料庫比對的問題

回復 8# fusayloveme

附帶一份比較容易的邏輯..

用C資料庫(sheet3) 分別列出相同與不同的判斷
  1. Sub ow()
  2.     Sheets("A資料庫").Select
  3.     Range("a3", "C65535").Select
  4.     Selection.Copy
  5.     Sheets("Sheet3").Select
  6.     Range("m3").Select
  7.     ActiveSheet.Paste
  8.    
  9.     Sheets("B資料庫").Select
  10.     Range("a3", "C65535").Select
  11.     Selection.Copy
  12.     Sheets("Sheet3").Select
  13.     Range("P3").Select
  14.     ActiveSheet.Paste
  15.         Range("A3", "F65535").Value = Range("M3", "R65535").Value
  16.    
  17. If Range("a3").Value <> "" Then
  18.     For xk = 3 To 65536
  19.    
  20.         
  21.         If Range("D" & xk).Value <> Range("A" & xk).Value Then
  22.                         Range("h" & xk).Value = "A欄位  比對失敗"
  23.                         Range("A" & xk).Select
  24.                             With Selection.Interior
  25.                                 .Pattern = xlSolid
  26.                                 .PatternColorIndex = xlAutomatic
  27.                                 .Color = 65535
  28.                                 .TintAndShade = 0
  29.                                 .PatternTintAndShade = 0
  30.                             End With
  31.                         Range("D" & xk).Select
  32.                             With Selection.Interior
  33.                                 .Pattern = xlSolid
  34.                                 .PatternColorIndex = xlAutomatic
  35.                                 .Color = 65535
  36.                                 .TintAndShade = 0
  37.                                 .PatternTintAndShade = 0
  38.                             End With
  39.         End If
  40.         If Range("P" & xk).Value = Range("m" & xk).Value Then
  41.             'Range("H" & XK).Value = "A欄位比對成功"
  42.             Range("A" & xk, "F" & xk).Value = Range("M" & xk, "R" & xk).Value
  43.             If Range("D" & xk).Value = Range("a" & xk).Value Then
  44.                 If Range("E" & xk).Value = Range("b" & xk).Value Then
  45.                     If Range("f" & xk).Value = Range("c" & xk).Value Then
  46.                         Range("h" & xk).Value = "比對成功"
  47.                     End If
  48.                     If Range("f" & xk).Value <> Range("c" & xk).Value Then
  49.                         Range("h" & xk).Value = "C欄位  比對失敗"
  50.                         Range("F" & xk).Select
  51.                             With Selection.Interior
  52.                                 .Pattern = xlSolid
  53.                                 .PatternColorIndex = xlAutomatic
  54.                                 .Color = 65535
  55.                                 .TintAndShade = 0
  56.                                 .PatternTintAndShade = 0
  57.                             End With
  58.                         Range("C" & xk).Select
  59.                             With Selection.Interior
  60.                                 .Pattern = xlSolid
  61.                                 .PatternColorIndex = xlAutomatic
  62.                                 .Color = 65535
  63.                                 .TintAndShade = 0
  64.                                 .PatternTintAndShade = 0
  65.                             End With
  66.                     
  67.                     End If
  68.                 End If
  69.                 If Range("e" & xk).Value <> Range("b" & xk).Value Then
  70.                         Range("h" & xk).Value = "B欄位  比對失敗"
  71.                         Range("E" & xk).Select
  72.                             With Selection.Interior
  73.                                 .Pattern = xlSolid
  74.                                 .PatternColorIndex = xlAutomatic
  75.                                 .Color = 65535
  76.                                 .TintAndShade = 0
  77.                                 .PatternTintAndShade = 0
  78.                             End With
  79.                         Range("B" & xk).Select
  80.                             With Selection.Interior
  81.                                 .Pattern = xlSolid
  82.                                 .PatternColorIndex = xlAutomatic
  83.                                 .Color = 65535
  84.                                 .TintAndShade = 0
  85.                                 .PatternTintAndShade = 0
  86.                             End With
  87.                         
  88.                 End If
  89.             End If
  90.    
  91.         End If
  92.         'If Range("P" & XK).Value <> Range("m" & XK).Value Then
  93.         '    Range("H" & XK).Value = "A欄位  比對失敗"
  94.         '    Range("A" & XK, "F" & XK).Value = Range("M" & XK, "R" & XK).Value
  95.         'End If
  96.    
  97.    
  98.     Next xk
  99. End If
  100.         Columns("M:R").Select
  101.         Range("M2").Activate
  102.         Selection.Delete Shift:=xlToLeft


  103. End Sub
複製代碼

TOP

回復 11# mark15jill

非常感謝!! 晚點來試試看,目前突然接到不小的工作量,晚點來測試看看 ^_^

TOP

回復 11# mark15jill

mark大大,太棒嚕,這個周末有空再來修改一下,有不懂的問題再請教您,非常感謝您 ^_^

TOP

回復 13# fusayloveme

不會啦
因為你問的問題
之前我就問過類似的了= ="
只是 我問的比較亂點..
你只是單純 A B 比對..
之前我問的是 A B 比對後 如果 確定是我要的  就從其他檔案內 代入數據
如 AAA.xls 和  BBB.xls 比對後
在CCC.xls 內 代入 甲甲甲.xls的儲存格數據..

這方法適用於  表格資料的轉換
有些原先設定的表格  填入數據後
直接  代入到想要的儲存格內並且去判斷格式是否正確..

或者 從 儲存格 比對後把資料 轉成 我要的型態..+.+

TOP

        靜思自在 : 並非有錢魷是快樂,問心無愧心最安。
返回列表 上一主題