返回列表 上一主題 發帖

請教搜尋名稱 找出日期 謝謝

回復 19# mycmyc
也可用 Application.Match函數
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Rng(1 To 2) As Range, e As Range, M As Variant, d As Object
  4.      With Sheets("工作表2")
  5.         .UsedRange.Clear
  6.         .[a1:b1] = Array("日期", "施工項目")
  7.     End With
  8.     With Sheets("工作表1")
  9.         Set Rng(1) = .Range("B6", "B" & .[A6].End(xlDown).Row).Resize(, .[A1].End(xlToRight).Column - 1).SpecialCells(xlCellTypeConstants, 1)
  10.         ' ***   .SpecialCells(xlCellTypeConstants, 1)   是數字的儲存格  ***
  11.         For Each e In Rng(1)
  12.             M = Application.Match(.Cells(e.Row, 1).Text, Sheets("工作表2").Columns(1), 0)
  13.             If IsError(M) Then                             'Match不到                 '
  14.                 Set Rng(2) = Sheets("工作表2").Range("A" & Rows.Count).End(xlUp).Offset(1)
  15.                 Rng(2) = .Cells(e.Row, 1).Text             'A欄的日期
  16.                 Rng(2).Cells(1, 2) = .Cells(1, e.Column)   '第一列的施工項目
  17.             Else
  18.                 Set Rng(2) = Sheets("工作表2").Range("A" & M)   'Match到 的列號
  19.                 Rng(2).Cells(1, 2) = Rng(2).Cells(1, 2) & "、" & .Cells(1, e.Column)
  20.             End If
  21.         Next
  22.     End With
  23. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

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