返回列表 上一主題 發帖

問題!!搜尋值回傳

本帖最後由 yen956 於 2014-2-27 18:52 編輯

回復 1# kevin21522886
試試看:
  1. Option Explicit

  2. Sub 最新版()
  3.     Dim x, y As Worksheet
  4.     Dim cnt, i As Integer
  5.     Dim Rng, FindCell As Range
  6.     Dim FindStr As String
  7.     Set x = Sheets(1)
  8.     cnt = ThisWorkbook.Sheets.Count
  9.     For Each Rng In x.[B2].Resize(x.[B2].End(xlDown).Row - 1, 1)
  10.         For i = cnt To 2 Step -1
  11.             Set y = Sheets(i)
  12.             y.Activate
  13.             Set FindCell = y.Cells.Find(What:=Rng.Value, After:=ActiveCell, _
  14.                     LookIn:=xlFormulas, LookAt:=xlPart, _
  15.                     SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  16.                     MatchCase:=False, MatchByte:=False, SearchFormat:=False)
  17.             If Not FindCell Is Nothing Then
  18.                Rng.Offset(0, -1) = FindCell.Offset(0, -1)
  19.                Rng.Offset(0, 1) = FindCell.Offset(0, 1)
  20.                Exit For
  21.             End If
  22.         Next
  23.     Next
  24. End Sub
複製代碼

TOP

        靜思自在 : 吃苦了苦、苦盡廿來,享福了福、福盡悲來。
返回列表 上一主題