Vba array subtraction problem

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hello, I have been trying to work around this code and do not work, any help please.
I have a row of 6 numbers at E2:J2 and one dynamic array at L2:Q I am trying to subtracting each number from E2:J2 from the array and the results at S2:X, just to simplify let think as the row (E2:J2) is 1,1,1,1,1,1 and subtracting from the array is 2,2,2,2,2,2 all the way down, the results will be of course 1,1,1,1,1,1
Code:
Sub subtractone()

  Dim a
  Dim i As Long, j As Long, rws As Long
 
  With Range("E2", Range("L" & Rows.Count).End(xlUp)).Resize(, 24)
    a = .Value
    rws = UBound(a, 1)
    For i = 2 To rws
      For j = 1 To 6
        a(i, 14 + j) = Abs(a(1, j) - a(i, 12 + j))
      Next j
    Next i
    .Value = a
  End With


End Sub
I try this but I don't get the right results.
EFGHIJKLMNOPQRSTUVWX
2203040424449 101621294143 1014191336
3 121730434446 81310103
4 162027314041 410131148
5 ETC.
6
7
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this:-
Rich (BB code):
Sub MG28Oct28
Dim a
  Dim i As Long, j As Long, rws As Long
 
  With Range("E2", Range("L" & Rows.Count).End(xlUp)).Resize(, 20)
    a = .Value
    rws = UBound(a, 1)
    For i = 1 To rws
      For j = 1 To 6
        a(i, 14 + j) = Abs(a(1, j) - a(i, 7 + j))
      Next j
    Next i
    .Value = a
  End With

End Sub
Regards Mick
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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