- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
6#
發表於 2012-10-19 15:23
| 只看該作者
本帖最後由 GBKEE 於 2012-10-19 15:26 編輯
回復 5# JEAN
試試看- '[領用單]部門單位: B3 有變動 ->申請人名字: B4 會更著變動名單
- Private Sub CommandButton1_Click()
- 首頁
- End Sub
- Private Sub CommandButton2_Click()
- Sheets("領用記錄明細表").Visible = True
- Sheets("領用記錄明細表").Select
- Me.Visible = False
- End Sub
- Private Sub Worksheet_Activate() '製定部門單位的驗證, [領用單]工作表為作用中時的預設件
- Dim Ar As String, xI As Integer
- With Sheets("人員資料").[E2]
- xI = 2
- Do While .Cells(xI) <> ""
- If Ar = "" Then
- Ar = "," & .Cells(xI, 1)
- Else
- If InStr(Ar, "," & .Cells(xI)) & "," = 0 Then Ar = Ar & "," & .Cells(xI)
- End If
- xI = xI + 1
- Loop
- End With
- With Range("B3").Validation
- .Delete
- If Ar <> "" Then .Add xlValidateList, , , Mid(Ar, 2)
- End With
- End Sub
- Private Sub Worksheet_Change(ByVal Target As Range)
- Application.EnableEvents = False
- If Target(1).Address(0, 0) = "B3" Then
- If Target(1) = "" Then Range("B4") = ""
- 驗證B4
- End If
- Application.EnableEvents = True
- End Sub
- Private Sub 驗證B4()
- Dim Ar As String, xI As Integer
- With Sheets("人員資料").[A2]
- xI = 2
- Do While .Cells(xI) <> ""
- If .Cells(xI) = [B3] Then
- If Ar = "" Then
- Ar = "," & .Cells(xI, 3) '中文姓名 在第3欄
- Else
- If InStr(Ar, "," & .Cells(xI, 3) & ",") = 0 Then Ar = Ar & "," & .Cells(xI, 3)
- End If
- End If
- xI = xI + 1
- Loop
- End With
- With Range("B4").Validation
- .Delete
- If Ar <> "" Then .Add xlValidateList, , , Mid(Ar, 2)
- End With
- End Sub
複製代碼 |
|