Find and copy negative values and then change them

tintin1012000

Board Regular
Joined
Apr 27, 2011
Messages
237
Easy for someone maybe

I need to find all negative values in range A1 to C965

Then copy the values found and move them 3 colums over to the right. And also change the value from negative to positive.

Can it be done in vba
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This might be a little klunky, but it works

VBA Code:
Sub MoveAbsolute()
  Dim R As Range
  Dim OutR As Range
  
  Set R = Range("A1:C965")
  Set OutR = Range("D1:F965")
  
  Range("D1").Formula = "=Abs(A1)"
  OutR.Formula = Range("D1").Formula
  OutR.Value = OutR.Value
  
  
End Sub
 
Upvote 0
Hello Please try this and provide a feedback
VBA Code:
Sub check_negative()
Dim i As Integer
Dim j As Integer
For i = 1 To 965
For j = 1 To 3
    If Cells(i, j).Value < 0 Then
    Cells(i, j).Cut Cells(i, j + 3)
    End If
Next j
Next i
End Sub
 
Upvote 0
copy the values found and move them
i need it to only copy negatives
I am confused by this part of your request. (Sorry, my English is bad)

So, Copy or Move?

I know this VBA below may be simpler, but still maybe it is the solution to your requirement.
I have modified some VBA examples.
Code:
Sub CopyNegativeValueAndTransformToPositiveValue()
Dim Cel As Range
Dim i As Integer
Dim j As Integer
For i = 1 To 965
For j = 1 To 3
    If Cells(i, j).Value < 0 Then
    'Copy cells
    Cells(i, j).Copy Cells(i, j + 3) 'If you want MOVE type Cut
    End If
Next j
Next i
    Columns("D:F").Select
    Selection.SpecialCells(xlCellTypeConstants, 23).Select
    For Each Cel In Selection
        If IsNumeric(Cel.Value) Then
            Cel.Value = Abs(Cel.Value)
        End If
    Next Cel
Range("D1").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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