上節(jié)我們講到了控件的增加和基礎(chǔ)代碼,今天繼續(xù)講解控件的觸發(fā)事件。 這一節(jié)的視頻內(nèi)容講解,講的不好,請(qǐng)不要見笑。 代碼就不解釋了,自己看視頻吧!想獲取本章的源代碼請(qǐng)和視頻資料請(qǐng)加微信:18622923987,或者直接淘寶掃描下面二維碼: 代碼如下: Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) ’文字輸入框的代碼 Dim i As Integer Dim Language As Boolean Dim myStr As String Me.ListBox1.Clear With Me.TextBox1 For i = 1 To Len(.Value) If Asc(Mid$(.Value, i, 1)) > 255 Or Asc(Mid$(.Value, i, 1)) < 0=""> Language = True myStr = myStr & Mid$(.Value, i, 1) Else myStr = myStr & LCase(Mid$(.Value, i, 1)) End If Next End With With Sheets('商品') For i1 = 2 To .Range('B65536').End(xlUp).Row If Language = True Then If Left(.Cells(i1, 3).Value, Len(myStr)) = myStr Then Me.ListBox1.AddItem .Cells(i1, 2).Value End If Else If Left(.Cells(i1, 3).Value, Len(myStr)) = myStr Then Me.ListBox1.AddItem .Cells(i1, 2).Value End If End If Next End With End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) ’表格選擇改變代碼 If Target.Column <> 1 And Cells(Range('a999999').End(xlUp).Row, 1) = '' Then Cells(Range('a999999').End(xlUp).Row + 1, 1).Select Else Dim i As Integer If Target.Count = 1 And ActiveCell = '' Then If Target.Column = 1 And Target.Row > 1 Then With Me.sj .Visible = True .Top = Target.Top .Left = Target.Left .Width = Target.Width .Height = Target.Height End With End If End If If Target.Count = 1 And ActiveCell = '' Then If Target.Column = 3 And Target.Row > 1 Then If Cells(Target.Row, Target.Column - 2) <> '' Then With Me.TextBox1 .Visible = True .Visible = True .Top = Target.Top .Left = Target.Left .Width = Target.Width .Height = Target.Height End With With Me.ListBox1 .Visible = True .Top = Target.Top .Left = Target.Offset(0, 1).Left .Width = Target.Width * 3 End With Else Exit Sub End If End If End If End If End Sub Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) ActiveCell.Value = ListBox1.Value Me.ListBox1.Clear Me.TextBox1 = '' Me.ListBox1.Visible = False Me.TextBox1.Visible = False Me.ListBox2.Visible = True Me.ListBox2.Clear For i11 = 2 To Sheets('商品').Range('B65536').End(xlUp).Row If Sheets('商品').Cells(i11, 2).Value = ActiveCell.Value Then ListBox2.AddItem Sheets('商品').Cells(i11, 1).Value & ' ( ' & Sheets('商品').Cells(i11, 4).Value End If Next ActiveCell.Offset(0, -1).Select With Me.ListBox2 .Top = ActiveCell.Top .Left = ActiveCell.Offset(0, 1).Left End With End Sub |
|