返回列表 上一主題 發帖

[發問] 如何經由表單的輸入,在清單找出對應的資料

本帖最後由 GBKEE 於 2014-8-20 07:17 編輯

回復 2# luhpro
  1. Private Sub CommandButton2_Click()
  2.         With Columns("A:C")
  3.             .ClearContents
  4.             'ClearContents 方法 清除範圍的公式。清除圖表中的資料但保留格式設定。
  5.             '****清除範圍的公式也包含清除範圍的字串***
複製代碼
試試看
  1. 'Sheet1模組的程式碼
  2. Option Explicit
  3. Dim d As Object
  4. Private Sub CommandButton1_Click()
  5.     Dim Text(1 To 2) As String
  6.     Text(1) = Trim(TextBox1)
  7.     Text(2) = Trim(TextBox2)  '樓主檔案有用到TextBox2
  8.     UsedRange.ClearFormats    '取代  清單CLEAR按鈕 , CommandButton2
  9.     If Text(1) <> "" And Text(2) <> "" Then
  10.         If d Is Nothing Then item_qty
  11.         If d.EXISTS(Text(1) & Text(2)) Then
  12.             d(Text(1) & Text(2)).Interior.ColorIndex = 44
  13.         End If
  14.     End If
  15. End Sub
  16. Private Sub item_qty()
  17.     Dim r As Range
  18.     Set d = CreateObject("scripting.dictionary") '字典物件
  19.     For Each r In UsedRange.Rows
  20.         'item(A攔)&qty(C攔)內容為字典物件key值,指定到 Range
  21.         Set d(r.Cells(1, 1) & r.Cells(1, 3)) = r.Cells(1, 1).Resize(, 3)        
  22.     Next
  23. End Sub
複製代碼
不用使用 CommandButton1,
TextBox1,TextBox2 有改變直接顯示
  1. 'Sheet1模組的程式碼
  2. Option Explicit
  3. Dim d As Object
  4. Private Sub TextBox1_Change()
  5.     Ex
  6. End Sub

  7. Private Sub TextBox2_Change()
  8.     Ex
  9. End Sub
  10. Private Sub Ex()
  11.     Dim Text(1 To 2) As String
  12.     Text(1) = Trim(TextBox1)
  13.     Text(2) = Trim(TextBox2)  '樓主檔案有用到TextBox2
  14.     UsedRange.ClearFormats    '取代  清單CLEAR按鈕 , CommandButton2
  15.     If Text(1) <> "" And Text(2) <> "" Then
  16.         If d Is Nothing Then item_qty
  17.         If d.EXISTS(Text(1) & Text(2)) Then
  18.             d(Text(1) & Text(2)).Interior.ColorIndex = 44
  19.         End If
  20.     End If
  21. End Sub
  22. Private Sub item_qty()
  23.     Dim r As Range
  24.     Set d = CreateObject("scripting.dictionary") '字典物件
  25.     For Each r In UsedRange.Rows
  26.         'item(A攔)&qty(C攔)內容為字典物件key值,指定到 Range
  27.         Set d(r.Cells(1, 1) & r.Cells(1, 3)) = r.Cells(1, 1).Resize(, 3)
  28.         
  29.     Next
  30. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2014-8-23 10:41 編輯
另, Range 的 Copy 指令使用時,
若只有指定 Destination 而無其他特殊需求,
則 Destination:= 可以不用列出來,
只要打 Cells(2, 8).Copy Cells(3, 8) 即可.
luhpro 發表於 2014/8/23 09:25


是可不指明第一個參數的名稱

expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
不指明需   , , , expression.Find( "TEST", , , , , , ,  ,  TRUE)
指明可省略 , , , expression.Find( "TEST",  SearchFormat:=True)
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 君子為目標,小人為目的。
返回列表 上一主題