我有这样的桌子
Column A Column B
5 25
4 20
8 40
3 15
20 100
我想使用vba脚本从A列中选择最后一个值,以像=A1/last Value Form coumn A*100
一样进行划分
答案 0 :(得分:1)
答案 1 :(得分:1)
如果您正在Excel-VBA
中寻找解决方案,那么就在这里。
Sub test()
Dim result As Variant
Dim firstvalue As Variant
Dim secondvalue As Variant
firstvalue = Range("A1").Value
secondvalue = Range("A" & Cells(Rows.Count, 2).End(xlUp).Row).Value
result = (firstvalue / secondvalue) * 100
End Sub
答案 2 :(得分:0)
使用VBA。它使用一个快速的数组,并完成整个列,如图所示。
Option Explicit
Public Sub DivideByLastValue()
Dim lastRow As Long, arr(), i As Long, divisor As Double
With ThisWorkbook.Worksheets("Sheet1")
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
arr = .Range("A1:B" & lastRow).Value
divisor = arr(UBound(arr, 1), 1)
For i = LBound(arr, 1) To UBound(arr, 1)
arr(i, 2) = arr(i, 1) / divisor * 100
Next
.Cells(1, 1).Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
End Sub