Vba array subtraction problem

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
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.
[TABLE="width: 1344"]
[TR]
[TD="class: xl65, width: 64"] [/TD]
[TD="class: xl66, width: 64"]E[/TD]
[TD="class: xl66, width: 64"]F[/TD]
[TD="class: xl66, width: 64"]G[/TD]
[TD="class: xl66, width: 64"]H[/TD]
[TD="class: xl66, width: 64"]I[/TD]
[TD="class: xl66, width: 64"]J[/TD]
[TD="class: xl66, width: 64"]K[/TD]
[TD="class: xl66, width: 64"]L[/TD]
[TD="class: xl66, width: 64"]M[/TD]
[TD="class: xl66, width: 64"]N[/TD]
[TD="class: xl66, width: 64"]O[/TD]
[TD="class: xl66, width: 64"]P[/TD]
[TD="class: xl66, width: 64"]Q[/TD]
[TD="class: xl66, width: 64"]R[/TD]
[TD="class: xl66, width: 64"]S[/TD]
[TD="class: xl66, width: 64"]T[/TD]
[TD="class: xl66, width: 64"]U[/TD]
[TD="class: xl66, width: 64"]V[/TD]
[TD="class: xl66, width: 64"]W[/TD]
[TD="class: xl66, width: 64"]X[/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]2[/TD]
[TD="class: xl65, align: right"]20[/TD]
[TD="class: xl65, align: right"]30[/TD]
[TD="class: xl65, align: right"]40[/TD]
[TD="class: xl65, align: right"]42[/TD]
[TD="class: xl65, align: right"]44[/TD]
[TD="class: xl65, align: right"]49[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]10[/TD]
[TD="class: xl65, align: right"]16[/TD]
[TD="class: xl65, align: right"]21[/TD]
[TD="class: xl65, align: right"]29[/TD]
[TD="class: xl65, align: right"]41[/TD]
[TD="class: xl65, align: right"]43[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]10[/TD]
[TD="class: xl65, align: right"]14[/TD]
[TD="class: xl65, align: right"]19[/TD]
[TD="class: xl65, align: right"]13[/TD]
[TD="class: xl65, align: right"]3[/TD]
[TD="class: xl65, align: right"]6[/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]3[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]12[/TD]
[TD="class: xl65, align: right"]17[/TD]
[TD="class: xl65, align: right"]30[/TD]
[TD="class: xl65, align: right"]43[/TD]
[TD="class: xl65, align: right"]44[/TD]
[TD="class: xl65, align: right"]46[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]8[/TD]
[TD="class: xl65, align: right"]13[/TD]
[TD="class: xl65, align: right"]10[/TD]
[TD="class: xl65, align: right"]1[/TD]
[TD="class: xl65, align: right"]0[/TD]
[TD="class: xl65, align: right"]3[/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]4[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]16[/TD]
[TD="class: xl65, align: right"]20[/TD]
[TD="class: xl65, align: right"]27[/TD]
[TD="class: xl65, align: right"]31[/TD]
[TD="class: xl65, align: right"]40[/TD]
[TD="class: xl65, align: right"]41[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65, align: right"]4[/TD]
[TD="class: xl65, align: right"]10[/TD]
[TD="class: xl65, align: right"]13[/TD]
[TD="class: xl65, align: right"]11[/TD]
[TD="class: xl65, align: right"]4[/TD]
[TD="class: xl65, align: right"]8[/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]5[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"]ETC.[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]6[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl67, align: right"]7[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[/TABLE]
 
Last edited by a moderator:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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