我试图通过vlookup查找范围,然后通过除以数字来更改其先前的值。 该代码可以很好地找到范围,但是它将第一个单元格值放入范围内的所有单元格中,然后进行除法。
当我使用TRY-1时,它将“ 2500”值正确地放置在范围内 但是,当我使用try 2 It时,它仅显示范围中的第一个单元格值,然后将其除以除法器,然后放入整个范围中
包含图片
Sub SPLITS()
Dim Lookup_1 As Variant, Lookup_2 As Variant
Dim WsSplit As Worksheet
Dim LR As Long, LRN As Long, x As Long
Dim a As Range, b As Range
Set WsSplit = ThisWorkbook.Worksheets("Student")
LR = WsSplit.Range("A" & Rows.Count).End(xlUp).Row
LRN = WsSplit.Range("C" & Rows.Count).End(xlUp).Row
With WsSplit
On Error Resume Next
For x = 2 To LR
Set a = Application.Index(WsSplit.Range("E14:E" & LRN), Application.Match(.Cells(x, 1).Value, WsSplit.Range("C14:C" & LRN), 0))
Set b = Application.Index(WsSplit.Range("F14:F" & LRN), Application.Match(.Cells(x, 1).Value, WsSplit.Range("C14:C" & LRN), 0))
'/Old Values
Lookup_1 = Application.Index(WsSplit.Range((.Cells(x, a.Value)), .Cells(x, b.Value)).Value, _
Application.Match(.Cells(x, 1).Value, WsSplit.Range("C14:C" & LRN), 0))
'/Divider
Lookup_2 = Application.Index(WsSplit.Range("G14:G" & LRN), Application.Match(.Cells(x, 1).Value, WsSplit.Range("C14:C" & LRN), 0))
'/TRY-1
'.Range((.Cells(x, a.Value)), .Cells(x, b.Value)).Value = 5000 / 2
'/TRY-2
.Range((.Cells(x, a.Value)), .Cells(x, b.Value)).Value = Lookup_1 / Lookup_2
Next x
End With
End Sub