AR = Application.Transpose(Application.Transpose(AR))
For i = 1 To UBound(AR)
A = Application.WorksheetFunction.Index(AR, i)
If InStr(UCase(Join(A, ",")), UCase(Msg)) = 1 Then
EX_地區 = A(3)
Exit For
End If
Next
End Function
複製代碼
作者: 周大偉 時間: 2014-12-10 18:45
本帖最後由 周大偉 於 2014-12-10 18:46 編輯
感謝兩位樓主回應, 先行謝過,
小弟真的沒法把現使用的程式與兩位大大所供的程式融合, 現把使用開的程式貼上, 請兩位樓主協助, 謝謝!!
Private Sub Worksheet_Change(ByVal T As Range)
Dim Rng As Range, A As Range, Dha As Workbook, pp
Application.EnableEvents = False
Set Dha = Workbooks("sss倉庫資料.xlsm")
Set Rng = Dha.Sheets(1).UsedRange
Select Case T.Column
Case 2
If IsDate(T) Then T.Offset(, -1) = Month(T)
Case 3
Set A = Rng.Columns(2).Find(T, lookat:=xlWhole)
If A Is Nothing Then MsgBox "無此貨物編號": GoTo 10
T.Offset(, 1) = A.Offset(, 1)
T.Offset(, 2) = A.Offset(, 2)
T.Offset(, 3) = A.Offset(, 3)
T.Offset(, 5) = A.Offset(, 4)
Case 7
Set A = Rng.Columns(2).Find(T.Offset(, -4), lookat:=xlWhole)
pp = Application.SumIf(Range("C:G"), A, Range("G:G")) '計算倉庫提取總數
If pp > (A.Offset(, 8) + A.Offset(, 10)) Then
MsgBox T.Offset(, -3) & "存量不足重新填寫"
T.Interior.ColorIndex = 26
GoTo 10
End If
T.Interior.ColorIndex = xlNone
pp = Application.SumIf(Range("C:G"), T.Offset(, -4), Range("G:G")) '計算倉庫提取總數
A.Offset(, 8) = pp
A.Offset(, 10) = A.Offset(, 7) + A.Offset(, 9) - A.Offset(, 8)
T.Offset(, 2) = T * T.Offset(, 1)
Dha.Save
End Select
10
Application.EnableEvents = True
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal T As Range, Cancel As Boolean)
Dim A As Range
If Not Application.Intersect(T, Range("A3:L" & Application.CountA([A3:A6]) + 2)) Is Nothing Then
Cancel = True
With Workbooks("sss倉庫資料.xlsm")
Set A = .Sheets(1).UsedRange.Columns(2).Find(Range("C" & T.Row), lookat:=xlWhole)
If A.Column <> 2 Or A = "" Then
MsgBox "資料不正確 請查明"
Range(Cells(T.Row, "A"), Cells(T.Row, "L")).Select
Exit Sub
End If
If MsgBox(Range("C" & T.Row) & " " & Range("D" & T.Row) & Chr(10) _
& "取消 " & [G2] & " " & Range("G" & T.Row) & Chr(10) & "請注意 [本紀錄] 取消後無法復原", vbYesNo) = vbYes Then
Application.ScreenUpdating = False
Application.EnableEvents = False
A.Offset(, 8) = Application.SumIf(Range("C:C"), A, Range("G:G")) - Range("G" & T.Row) '變更入貨總數於資料庫
A.Offset(, 10) = A.Offset(, 7) + A.Offset(, 9) - A.Offset(, 8)
.Save
Range(Cells(T.Row, "A"), Cells(T.Row, "L")).Delete (3)
Application.EnableEvents = True
ActiveWorkbook.Save
Application.ScreenUpdating = True
End If
End With
End If
End Sub作者: GBKEE 時間: 2014-12-11 06:42
回復 7#周大偉
請將你原本的 Private Sub Worksheet_Change(ByVal T As Range)
複製在工作表的模組上,修改程序名稱為
例 Private Sub Ex_Sub1(ByVal T As Range)
原本的 Private Sub Worksheet_Change(ByVal T As Range)事件
修改內容如下
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)