subtract columns

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
hello, I am trying to subtract columns and I write this code but results are complet wrong, is a dynamic array start A1:F250 , I am looking to subtract col B-A results on H, C-B results on I, D-C results on J etc. this is what I tryed.
Code:
Sub test()
'subtract b-a, c-b, d-c, e-d
'the results on H, I, J, K

Dim x As Integer
Dim y As Integer

    For x = 1 To 5
    For y = 1 To 4
    
        Cells(x, "h").Value = Cells(x, "h").Value - Cells(x, y).Value
        Cells(x, "I").Value = Cells(x, "i").Value - Cells(x, y).Value
        Cells(x, "j").Value = Cells(x, "j").Value - Cells(x, y).Value
        Cells(x, "k").Value = Cells(x, "h").Value - Cells(x, y).Value
    Next y
    Next x
    
End Sub
is just integers. thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
time after I answer myself

VBA Code:
Sub Sub_M()
         Dim Rw As Long, Cl As Long
                  For Rw = 1 To Cells(Rows.Count, "A").End(xlUp).Row
                        For Cl = 1 To 5
                                    Cells(Rw, 8 + Cl) = Abs(Cells(Rw, Cl) - Cells(Rw, Cl + 1))
                        Next Cl
                  Next Rw
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,491
Messages
6,125,104
Members
449,205
Latest member
ralemanygarcia

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