tags:

views:

164

answers:

2

in a if statement, how do i match a positive number with a negative one e.g. if 500 match with -500, cut and paste

one solution i thought of is changing one of the column by *-1 before i do anything but... Is there anyway i could rephase 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
+4  A: 

Have you tried using Abs

If (Abs(sh1.Cells(i, "H").Value) = Abs(sh2.Cells(j, "E").Value)) Then
astander
o great it worked. learn something today :) thanks
nsy
+1  A: 

The ABS function returns the absolute value, i.e. the positive value. So ABS(-14) = 14. You could use this around both values.

Joel Goodwin