如何避免使用select
并确实需要使用该功能,或者是否有更好的功能。
谢谢你的时间。
Sub Makro3()
Range("D5").Select: ActiveCell.FormulaR1C1 = "=INDEX(S_Skills_1[L],(MATCH(16622,S_Skills_1[ID])))"
x = Range("D5").Value
Range("D5").Select: ActiveCell.FormulaR1C1 = "=INDEX(S_Skills_2[L],(MATCH(16622,S_Skills_2[ID])))"
y = Range("D5").Value
Range("D5").Value = Application.WorksheetFunction.max(x, y)
Range("D6").Select: ActiveCell.FormulaR1C1 = "=INDEX(S_Skills_1[L],(MATCH(3446,S_Skills_1[ID])))"
A = Range("D6").Value
Range("D6").Select: ActiveCell.FormulaR1C1 = "=INDEX(S_Skills_2[L],(MATCH(3446,S_Skills_2[ID])))"
B = Range("D6").Value
Range("D6").Value = Application.WorksheetFunction.max(x, y)
End Sub
答案 0 :(得分:3)
试试这个。的 UNTESTED 强>
Sub Makro3()
X = Evaluate("=INDEX(S_Skills_1[L],(MATCH(16622,S_Skills_1[ID])))")
Y = Evaluate("=INDEX(S_Skills_2[L],(MATCH(16622,S_Skills_2[ID])))")
Range("D5").Value = Application.WorksheetFunction.Max(X, Y)
A = Evaluate("=INDEX(S_Skills_1[L],(MATCH(3446,S_Skills_1[ID])))")
B = Evaluate("=INDEX(S_Skills_2[L],(MATCH(3446,S_Skills_2[ID])))")
Range("D6").Value = Application.WorksheetFunction.Max(X, Y)
End Sub
答案 1 :(得分:0)
这是我的最终代码如果你想知道我需要什么。感谢@Siddharth Rout
Sub FindMatchingValue()
Dim dat1 As Variant: Dim dat2 As Variant
Dim SP1 As Range: Set SP1 = [T5:V500] 'Range("S_Skills_1") why I cant use named areas for columns ?
Dim SP2 As Range: Set SP2 = [W5:Y500]
Dim i As Long
Find1 = 16622
dat1 = SP1.Value
dat2 = SP2.Value
Find2 = 3446
Range("D5, D6, D12, D13").Value = 0
FirstCheck:
For i = 1 To 300
If dat1(i, 1) = Find1 Then _
X = (dat1(i, 3))
If dat2(i, 1) = Find1 Then _
Y = (dat2(i, 3))
Next
SecondCheck:
If Not X = 5 Or Y = 5 Then GoTo NoMore:
FullSkill:
For i = 1 To 300
If dat1(i, 1) = Find2 Then _
A = (dat1(i, 3))
If dat2(i, 1) = Find2 Then _
B = (dat2(i, 3))
Next
Range("D5, D12").Value = 5
Range("D6, D13").Value = Application.WorksheetFunction.max(A, B)
GoTo Finish:
NoMore:
Range("D5, D12").Value = Application.WorksheetFunction.max(X, Y)
Range("D6, D13").Value = 0
Finish:
Call L_Set
Call LockS
Range("D1").Select
End Sub