gpt4 book ai didi

vba - 有条件地检查正值与负值

转载 作者:行者123 更新时间:2023-12-04 21:13:22 24 4
gpt4 key购买 nike

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

最佳答案

您是否尝试过使用 Abs

If (Abs(sh1.Cells(i, "H").Value) = Abs(sh2.Cells(j, "E").Value)) Then

关于vba - 有条件地检查正值与负值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1700729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com