|
请教:如何将一个sheet表中的两个过程合在一起?
请教:如何将一个sheet表中的两个过程合在一起?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Row < 2 Then Exit Sub
If Target.Column <> 3 Then Exit Sub
vl = Target.Value
If Len(vl) > 1 Then Exit Sub
Target.Select
On Error Resume Next
Set sj = Worksheets("Sheet2")
ed = sj.[a65536].End(xlUp).Row
Set rg = sj.Range("a2:a" & ed).Find(vl, LookIn:=xlValues)
If rg Is Nothing Then Exit Sub
With Application.CommandBars.Add(Name:="mycell", Position:=msoBarPopup)
r0 = 1
r = rg.Row
Do While r > r0
r0 = r
With .Controls.Add(Type:=msoControlButton)
.Caption = rg.Value
.OnAction = "bbb"
End With
Set rg = sj.Range("a2:a" & ed).FindNext(rg)
If Not rg Is Nothing Then r = rg.Row
Loop
End With
If Application.CommandBars("Mycell").Controls.Count = 1 Then
Application.EnableEvents = False
Selection.Value = Application.CommandBars("Mycell").Controls(1).Caption
Application.EnableEvents = True
Else
Application.CommandBars("Mycell").ShowPopup
End If
Application.CommandBars("Mycell").Delete
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Row < 2 Then Exit Sub
If Target.Column <> 4 Then Exit Sub
vl = Target.Value
If Len(vl) > 3 Then Exit Sub
Target.Select
On Error Resume Next
Set sj = Worksheets("种类")
ed = sj.[a65536].End(xlUp).Row
Set rg = sj.Range("a2:a" & ed).Find(vl, LookIn:=xlValues)
If rg Is Nothing Then Exit Sub
With Application.CommandBars.Add(Name:="mycell", Position:=msoBarPopup)
r0 = 1
r = rg.Row
Do While r > r0
r0 = r
With .Controls.Add(Type:=msoControlButton)
.Caption = rg.Value
.OnAction = "bbb"
End With
Set rg = sj.Range("a2:a" & ed).FindNext(rg)
If Not rg Is Nothing Then r = rg.Row
Loop
End With
If Application.CommandBars("Mycell").Controls.Count = 1 Then
Application.EnableEvents = False
Selection.Value = Application.CommandBars("Mycell").Controls(1).Caption
Application.EnableEvents = True
Else
Application.CommandBars("Mycell").ShowPopup
End If
Application.CommandBars("Mycell").Delete
End Sub |
|