条件检查正值为负数 [英] Conditional check positive value against negative

查看:226
本文介绍了条件检查正值为负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果声明中,我如何将正数与负一个
进行匹配。如果500与-500匹配,剪切和粘贴

In a If statement, how do I match a positive number with a negative one e.g. if 500 matches with -500, cut and paste

我想到的一个解决方案是通过 * - 1 在我做任何事情之前,除了有无论如何我可以重新表述以下如果语句匹配一个阳性单元格和一个负单元格

One solution I thought of is changing one of the columns by *-1 before I do anything but is there anyway I could rephrase the below If statement to match a positive cell and a negative cell?

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

Have you tried using Abs

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

这篇关于条件检查正值为负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆