将一个范围内的每个单元格乘以一个值 [英] Multiplying every cell within a range by a value
本文介绍了将一个范围内的每个单元格乘以一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
范围(B1:B4)。值=范围(B1:B4)值* 4/7
$ b
解决方案
code> Range(B1:B4)Value = ActiveSheet.Evaluate(INDEX(B1:B4 * 4/7,))
之前:
之后:
Sub foo()
Dim t
t = Now()
[B:B] = ActiveSheet.Evaluate(INDEX(row(B:B)* 1,))
[B:B] = ActiveSheet.Evaluate(INDEX(B:B * ))
Dim x
Debug.Print(Now() - t)* 24 * 60 * 60
End Sub
将整个列B填充到单元格的行号,然后执行所需的数学。
花费2秒钟完成整个100万行。
I would like that the value of every cell within a range is multiplied by a specific value (let's say 4/7). I have this code, but I'm getting a "Type mismatch error".
Range("B1:B4").Value = Range("B1:B4").Value * 4 / 7
Any thoughts?
解决方案
This will do the whole at once:
Range("B1:B4").Value = ActiveSheet.Evaluate("INDEX(B1:B4 * 4 / 7,)")
Before:
After:
Just to show. I ran this:
Sub foo()
Dim t
t = Now()
[B:B] = ActiveSheet.Evaluate("INDEX(row(B:B)*1,)")
[B:B] = ActiveSheet.Evaluate("INDEX(B:B * 4 / 7,)")
Dim x
Debug.Print (Now() - t) * 24 * 60 * 60
End Sub
Which fills the entire column B with the row number of the cell, then does the math that is required.
It took 2 seconds to do the entire 1 million + rows.
这篇关于将一个范围内的每个单元格乘以一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文