montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 984
- Office Version
- 2010
- Platform
- 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
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]
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
[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: