請老師們幫小弟修改一下程式碼,2種的程式無法取得相融,附檔說明,謝謝!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xR As Range, MM
With Target
If .Columns.Count > 1 Then Exit Sub
If .Column <> 6 Then Exit Sub '可變更讀取欄位
If .Row < 2 Then Exit Sub
If Target.Count > 3 Then Application.ScreenUpdating = False
'超過三筆的,凍結執行過程,直到結束,加快執行速度
For Each xR In Target
With xR.Cells(1, 2)
.FormulaR1C1 = "=VLOOKUP(RC[-1],產品編號!C[-6]:C[-2],2,0)"
.Value = .Value
.Replace "#N/A", "", Lookat:=xlWhole '清除找不到符合編號的錯誤值
.Replace "0", "" '清除對應編號〔客戶名稱〕卻空白的0值
End With
Next
End With
With Target
If Target.Columns.Count > 1 Then Exit Sub
If Target.Column <> Range("M1").Column Then Exit Sub
For Each xR In Target
If xR = "" Then GoTo NEXT_CELL
MM = Application.Match(xR, Sheets("Sheet1").Range("A:A"), 0)
If IsError(MM) Then GoTo NEXT_CELL
xR = Sheets("Sheet1").Range("B" & MM).Value
NEXT_CELL:
Next
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 13 And Target.Count = 1 Then UserForm3.Show 0
If Target.Column = 6 And Target.Count = 1 Then UserForm4.Show 0
End Sub作者: 准提部林 時間: 2015-11-3 18:38
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xR As Range, MM
With Target
If .Columns.Count > 1 Then Exit Sub
If .Row < 2 Then Exit Sub
If .Column = [F1].Column Then
With .Offset(, 1)
.FormulaR1C1 = "=VLOOKUP(RC[-1],產品編號!C[-6]:C[-2],2,0)"
.Value = .Value
.Replace "#N/A", "", Lookat:=xlWhole
.Replace "0", ""
End With
ElseIf .Column = [M1].Column Then
On Error Resume Next
Application.EnableEvents = False
For Each xR In Target
MM = Application.Match(xR, Sheets("Sheet1").Range("A:A"), 0)
If IsNumeric(MM) Then xR = Sheets("Sheet1").Range("B" & MM).Value
Next
End If
End With
Application.EnableEvents = True
End Sub作者: man65boy 時間: 2015-11-3 21:01