Move negative value to next column

erodjob

Active Member
Joined
Feb 11, 2003
Messages
253
For excel 97

I need a macro that will look for a negative value and move it to row E.

So for range d1:d2000 if row d1 is "0" skip, if row d2 is 123.00 skip if row d3 is -125.00 then move it over to column e3. do until d2000.

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Sub neg()
n = 1
Do Until Cells(n,4) = ""
If Cells(n,4) < 0 then
Cells(n,5) = Cells(n,4)
Cellls(n,4).ClearContents
End If
n = n + 1
Loop
End Sub
 
Upvote 0
I get error type mismatch.

I am a noobie, and I'm sure you know what you are doing, but shouln't there be a reference to column d1: d2000?

I mean no disrespect, I am just learning. Also english is not my first language.

Thanks
 
Upvote 0
with n = 1 - cells(n,4) = Cells(1,4) which is the equivalent of saying Range("D1")

There's no need to reference the range as you're telling XL to run a loop on each row of Column D until such time as a row in D is blank at which point you want the loop to exit.

You are then saying to it - if the value in Column D is less than 0 then make Column E equal Column D before deleting the value in D.

The error is a typo I believe - change Cellls to Cells.
 
Upvote 0
try this, an extra L in cells.
I have amended so starts at cell D2 (cells 2,4) and ends at D2000 not first empty cell in col. D;

Sub neg()
n = 2
Do Until n = 2001
If Cells(n, 4) < 0 Then
Cells(n, 5) = Cells(n, 4)
Cells(n, 4).ClearContents
End If
n = n + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,522
Messages
6,125,312
Members
449,218
Latest member
Excel Master

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