返回列表 上一主題 發帖

(已解決)如何用搜尋找資料後複製該位置以下的資料?

回復  Hsieh


    仔細看過後板主的方式與另外一位大大方式不同(處理方式)
    如果說想要向另一位大 ...
freeffly 發表於 2012-2-23 09:09



    樓主你用的SHEET.Name是民國+年~
    所以H大大用sh = Format(a, "emm")的方式~ 來判斷你的SHEET名稱
    然後再進去那個SHEET中撈取資料
學習才能提升自己

TOP

回復 10# hugh0620
  1. r = Application.Match(a, .[A:A], 0)
  2.      If IsNumeric(r) And Not c Is Nothing Then a.Offset(, 2) = .Cells(r, c.Column) Else a.Offset(, 2) = ""
複製代碼

Match函數 :找到時傳回數字, 找不到時傳回 "#N/A" (錯誤值)
改成 If   Not IsError(r)  And Not c Is Nothing Then  就可以除錯

TOP

回復 8# freeffly
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Address = "$C$1" Then
  3. Application.EnableEvents = False
  4. Range("A1").CurrentRegion.Offset(1, 2) = ""
  5. For Each a In Range("A2", [A2].End(xlDown))
  6.   sh = Format(a, "emm")
  7.   For Each sht In Sheets
  8.   If sht.Name = sh Then
  9.   With sht
  10.      Set c = .Rows(1).Find([C1], lookat:=xlWhole)
  11.      r = Application.Match(a, .[A:A], 0)
  12.      If IsNumeric(r) And Not c Is Nothing Then a.Offset(, 2).Resize(, 2).Value = .Cells(r, c.Column).Resize(, 2).Value
  13.   End With
  14.   End If
  15.   Next
  16. Next
  17. End If
  18. Application.EnableEvents = True
  19. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 10# hugh0620


    這個我有發現
   你們倆各的處理方式不一樣
   都是學習的方式
字典兩各字 還真難理解

TOP

回復 13# Hsieh


    謝謝版主
   有想到用resize可是沒試出來
   原來是差在.value
字典兩各字 還真難理解

TOP

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