[英]copy and paste as negative 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
简单的乘法:
ws.Cells(r, "I").Value = -1 * ws.Cells(r + 1, "I").Value
可能最好在尝试乘法之前使用IsNumeric
:
With ws.Cells(r + 1, "I")
If IsNumeric(.Value) Then
ws.Cells(r, "I").Value = .Value * -1
End If
End With
我认为你可以通过只改变一行来做到这一点。 试试这个:
ws.Cells(r, "I").Value = 0 - ws.Cells(r + 1, "I").Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.