返回列表 上一主題 發帖

[發問] 更新資料但列位不同

回復 1# aok669
  1. Sub Ex()
  2. Dim d As Object, Rng As Range, R As Range, C As Range
  3. Set d = CreateObject("Scripting.Dictionary")
  4. With Sheets("in")
  5.     Set Rng = .Range("B2", .Cells(1, Columns.Count).End(xlToLeft).Offset(1)).Resize(.Cells(Rows.Count, 1).End(xlUp).Row - 1, .Cells(1, Columns.Count).End(xlToLeft).Column - 1)
  6.     For Each R In Rng.Rows
  7.         For Each C In R.Cells
  8.             d(.Cells(C.Row, 1) & .Cells(1, C.Column)) = C
  9.         Next
  10.     Next
  11. End With
  12. With Sheets("本")
  13.     Set Rng = .Range("B2", .Cells(1, Columns.Count).End(xlToLeft).Offset(1)).Resize(.Cells(Rows.Count, 1).End(xlUp).Row - 1, .Cells(1, Columns.Count).End(xlToLeft).Column - 1)
  14.     For Each R In Rng.Rows
  15.         For Each C In R.Cells
  16.             If d.EXISTS(.Cells(C.Row, 1) & .Cells(1, C.Column)) Then C = d(.Cells(C.Row, 1) & .Cells(1, C.Column))
  17.             
  18.         Next
  19.     Next
  20. End With
  21. End Sub
複製代碼

TOP

回復 3# Hsieh
樓主的檔案 "本"工作表中有一些欄位是 "IN"工作表所沒有的 直接複製整個工作表會覆蓋掉 "本" 原有的資料

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題