[英]copy and paste as negative value
I have developed below code and i want that it should paste the value as negative instead of positive value.我开发了下面的代码,我希望它应该将值粘贴为负值而不是正值。 I looked around but nothing similar found.
我环顾四周,但没有发现类似的东西。
It should be negative ws.Cells(r, "I").Value
它应该是负的
ws.Cells(r, "I").Value
Sub copyandpasteasnegative()
Dim ws As Worksheet, LastRow As Long, r As Long
Set ws = Sheet1
LastRow = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
For r = 2 To LastRow
If ws.Cells(r, "B") = "KIO" Then
ws.Cells(r, "I").Value = ws.Cells(r + 1, "I").Value
End If
Next
End Sub
Simple multiplication:简单的乘法:
ws.Cells(r, "I").Value = -1 * ws.Cells(r + 1, "I").Value
Probably best to use IsNumeric
before attempting to multiply:可能最好在尝试乘法之前使用
IsNumeric
:
With ws.Cells(r + 1, "I")
If IsNumeric(.Value) Then
ws.Cells(r, "I").Value = .Value * -1
End If
End With
I think you can do this by changing only one line.我认为你可以通过只改变一行来做到这一点。 Try this:
试试这个:
ws.Cells(r, "I").Value = 0 - ws.Cells(r + 1, "I").Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.