VBA comparing signs of rows in 2 columns

zeno

Board Regular
Joined
Feb 16, 2012
Messages
71
Hi,

I am comparing the signs of rows in 2 columns. If the sign is different, I want to multiply the 2nd column by (-1). I have the code below, but it is not working.


Code:
For k = 2 to k
    If sgn(k,"O")<>sgn(k,"P") then range("P"&k)*(-1)
Next k
   End If
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try

If sgn(Cells(k,"O"))<>sgn(Cells(k,"P")) then range("P"&k).Value = Range("P"&k)*-1
 
Upvote 0

Forum statistics

Threads
1,216,728
Messages
6,132,355
Members
449,720
Latest member
NJOO7

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top