|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim vLookupResult As Variant
- Dim multiplier As Double
- Dim multipliers As Variant
- Dim i As Long
- Dim dict As Object
-
- If Not Intersect(Target, Me.Range("Y11")) Is Nothing Then
- Application.EnableEvents = False
-
- Set dict = CreateObject("Scripting.Dictionary")
- multipliers = Array("困气1", 0.8, "困气2", 0.6, "困气3", 0.4, "困气4", 0.2, "困气5", 0.1)
- For i = LBound(multipliers) To UBound(multipliers) Step 2
- dict(multipliers(i)) = multipliers(i + 1)
- Next i
-
- On Error Resume Next
- vLookupResult = Application.WorksheetFunction.VLookup(Me.Range("BQ7").Value, ThisWorkbook.Sheets("胶料性能表").Range("$A$1:$AA$416"), 20, False)
- If err.Number <> 0 Then
- MsgBox "未找到对应的值"
- Application.EnableEvents = True
- Exit Sub
- End If
- On Error GoTo 0
-
- If dict.exists(Me.Range("Y11").Value) Then
- multiplier = dict(Me.Range("Y11").Value)
- Me.Range("Y10").Value = vLookupResult * multiplier
- Else
- MsgBox "Y11中的值不在预定义的乘数列表中"
- End If
-
- Application.EnableEvents = True
- End If
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|