返回列表 上一主題 發帖

[發問] 如何依名稱作為搜尋條件,將所有符合資料一併秀出在註解(修改)

[發問] 如何依名稱作為搜尋條件,將所有符合資料一併秀出在註解(修改)

本帖最後由 starry1314 於 2018-1-30 17:36 編輯

想請問如何依名稱作為搜尋條件後往右一欄並將所有符合條件一併顯示在注解 依名稱 注解顯示 食材內容.rar (32.36 KB)
因目前程式碼在做資料修改的時候,需要特地在KEY一次此格式的資料
希望以原本資料庫的格式做讀取,就不用另外在key in一次
  1. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  2. Dim xF As Range
  3. With Target.Item(1)
  4.       If .Column <> 3 Then Exit Sub
  5.       Cancel = True
  6.       If Not .Comment Is Nothing Then .ClearComments: Exit Sub
  7.       If .Value = "" Then Exit Sub
  8.       Set xF = Sheets("菜單(勿動)").[B:B].Find(.Value, Lookat:=xlWhole)
  9.       If xF Is Nothing Then Exit Sub
  10.       .NoteText xF & Chr(10) & xF(1, 2).Text
  11.       .Comment.Visible = True
  12. End With
  13. End Sub
複製代碼

已解決!
使用SQL再循序讀取

TOP

回復 2# starry1314
  1. Option Explicit
  2. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  3.     Dim xF As Range, St As String
  4.     With Target.Item(1)
  5.         If .Column <> 3 Then Exit Sub
  6.         Cancel = True
  7.         .ClearComments
  8.         Set xF = Sheets("菜單(勿動)").[B:B].Find(.Value, Lookat:=xlWhole)
  9.         If Not xF Is Nothing Then
  10.             .NoteText xF & "," & xF(1, 2).Text
  11.             St = xF(1, 2)
  12.             Do
  13.                 Set xF = Sheets("菜單(勿動)").[B:B].FindNext(xF)
  14.                 If xF(1, 2) = St Then Exit Do
  15.                 .NoteText .NoteText & Chr(10) & xF & "," & xF(1, 2).Text
  16.             Loop
  17.             .Comment.Visible = True
  18.         End If
  19.     End With
  20. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# GBKEE


    感謝版大,簡潔有力 執行又迅速

TOP

        靜思自在 : 發脾氣是短暫的發瘋。
返回列表 上一主題