I have a big data excel file, there are many negative numbers. Now I want to highlight all the negative values and then multiply it with a specific number (for example 0.5). Could you kindly show me how to do it?
Thank you.
Thank you.
Option Explicit
Sub multifly()
Dim i&, j&, lcell As Range, rng, n, t
t = Timer
n = 0.5
Set lcell = ActiveSheet.UsedRange.SpecialCells(xlLastCell)
rng = Range("A1", lcell).Value
For i = 1 To lcell.Row
For j = 1 To lcell.Column
If rng(i, j) < 0 Then rng(i, j) = rng(i, j) * n
Next
Next
Range("A1", lcell).Value = rng
MsgBox Timer - t
End Sub
chỉ cần chính xác với đủ dữ liệu là được, thời gian không quan trọng ạ.It took 6s for range "A1:ZZ10000" (10,000 rows * 702 columns)
Does it annoy too much?
VBA Code:Option Explicit Sub multifly() Dim i&, j&, lcell As Range, rng, n, t t = Timer n = 0.5 Set lcell = ActiveSheet.UsedRange.SpecialCells(xlLastCell) rng = Range("A1", lcell).Value For i = 1 To lcell.Row For j = 1 To lcell.Column If rng(i, j) < 0 Then rng(i, j) = rng(i, j) * n Next Next Range("A1", lcell).Value = rng MsgBox Timer - t End Sub
Have you given it a shot?chỉ cần chính xác với đủ dữ liệu là được, thời gian không quan trọng ạ.
Not yet, I will try it after finishing the remaining work and tell you. Moreover, the speed is not important, I only need the accuracy and to make sure every negative number is multiplied.Have you given it a shot?
And, does it work?
Sub multifly()Have you given it a shot?
And, does it work?