nsy*_*nsy 1 excel vba excel-vba
在If声明中,如何将正数与负数匹配,例如,如果500匹配-500,则剪切和粘贴
我想到的一个解决方案是*-1在我做任何事情之前更改其中一个列,但无论如何我可以改写下面的If语句以匹配正单元格和负单元格?
Dim sh1 As Worksheet, sh2 As Worksheet
Dim j As Long, i As Long, lastrow1 As Long, lastrow2 As Long
Set sh1 = Worksheets("WorksheetA")
Set sh2 = Worksheets("WorksheetB")
lastrow1 = sh1.Cells.SpecialCells(xlCellTypeLastCell).Row
lastrow2 = sh2.Cells.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To lastrow1
For j = 1 To lastrow2
If sh1.Cells(i, "H").Value = sh2.Cells(j, "E").Value Then
sh2.Cells(j, "O").Value .Cut sh1.Cells(i, "L").Value
End If
Next j
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
你尝试过使用过Abs吗?
If (Abs(sh1.Cells(i, "H").Value) = Abs(sh2.Cells(j, "E").Value)) Then
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1345 次 |
| 最近记录: |