Adding sequential cells in a row after vlookup - excel

Is there another method of doing this calculation that will allow me to drag across cells and have the column index range adjust accordingly?
{=SUM(VLOOKUP(value,array,{1,2,3,4},0))}
The column index numbers unfortunately don't increase (ie. {1,2,3,4} --> {2,3,4,5} etc..) using this formula. Any suggestions on how to go about this without having to input manually?
Any help would be much appreciated!

I suggest you to use COLUMN() function that returns number of the current column that you called it.
In column B : Column() = 2
And when you are using this function at your current format:
In column K : Column() = 11
Column()- 11 + 1 = 1
Column()- 11 + 2 = 2
Column()- 11 + 3 = 3
Column()- 11 + 4 = 4
Now with copying it to column L : Column() = 12
Column()- 11 + 1 = 2
Column()- 11 + 2 = 3
Column()- 11 + 3 = 4
Column()- 11 + 4 = 5

Related

Grouped Sum on complicated calculated fields in other column

I have an excel sheet with data (Sheet1). First number is a secuencial number representing a number of month.
Sheet1 <month, year, data1, data2>
[first row: titles]
1 1 data11 data12
2 1 data21 data22
3 1 data31 data32
4 1 data41 data42
5 1 data51 data52
6 1 data61 data62
7 1 data71 data72
8 1 data81 data82
9 1 data91 data92
10 1 data101 data102
11 1 data111 data112
12 1 data121 data122
13 2 data131 data132
14 2 data141 data142
Sheet2
[month, year, formule]
1 1 sheet1!C2-3*sheet1!B1
2 1 sheet1!C3-3*sheet1!B2
3 1 sheet1!C4-3*sheet1!B3
4 1 sheet1!C5-3*sheet1!B4
5 1 sheet1!C6-3*sheet1!B5
6 1 sheet1!C7-3*sheet1!B6
7 1 sheet1!C8-3*sheet1!B7
8 1 sheet1!C9-3*sheet1!B8
9 1 sheet1!C10-3*sheet1!B9
10 1 sheet1!C11-3*sheet1!B10
11 1 sheet1!C12-3*sheet1!B11
12 1 sheet1!C13-3*sheet1!B12
13 2 sheet1!C14-3*sheet1!B13
14 2 sheet1!C15-3*sheet1!B114
Sheet3
[year, Sum of column C in sheet2 grouped by year]
Firts row <year,formule>
1 =SUMIF(sheet2!B$2:B$15, A2, sheet!C$2:C$15)
2 =SUMIF(sheet2!B$2:B$15, A3, sheet!C$2:C$15)
My question, Can I remove and do the calculation in Sheet3
I can if the column C of sheet2 is moved to sheet1 but I don't want to put many columns in sheet1 because Sheet2 has many columns. If we can remove Sheet2, we removing a lot of formula (in this example 14 + 2 formules -> only 2 formules)
Thanks
Solved: The year is in column 2 then
=SUMPRODUCT((Sheet1!B$2:B$424=Sheet3!B2)*(Formula using $2:$424 in each column of the mensual formula))

Python recursive index changing

I am trying to arrange matrix in way that it will dynamically change the indexes.
I have tried to do it by means of for loop, however it only does once for each index.
def arrangeMatrix(progMatrix):
for l in range(len(progMatrix)):
for item in range(len(progMatrix[l])):
if indexExists(progMatrix,l + 1,item) and progMatrix[l + 1][item] == " ":
progMatrix[l + 1][item] = progMatrix[l][item]
progMatrix[l][item] = " "
The original list is:
1 0 7 6 8
0 5 5 5
2 1 6
4 1 3 7
1 1 1 7 5
And my code should fill all gapped indexes from up to bottom, however my result is:
1 0 6 8
0 5 5
2 1 7
4 1 3 7 6
1 1 1 7 5 5
The actual result should be:
1 0
0 5 8
2 1 7 5
4 1 3 7 6 6
1 1 1 7 5 5
Any help or hint is appreciated.Thanks in advance
It is probably easier if you first iterate the columns, since the change that happens in one column is independent on what happens in other columns. Then, per column, you could iterate the cells from the bottom to the top and keep track of the y-coordinate where the next non-space should "drop down" to.
No recursion is needed.
Here is how that could be coded:
def arrangeMatrix(progMatrix):
for x in range(len(progMatrix[0])):
targetY = len(progMatrix)-1
for y in range(len(progMatrix)-1,-1,-1):
row = progMatrix[y]
if row[x] != " ": # Something to drop down
if y < targetY: # Is it really to drop any lower?
progMatrix[targetY][x] = row[x] # copy it down
row[x] = " " # ...and clear the cell where it dropped from
targetY -= 1 # since we filled the target cell, the next drop would be higher

Is there a way to do a nested FOR loop in Excel?

If have the following two columns with the values:
A B
1 1
2 2
3 3
4 4
How can I multiply and return the sum:
1* 1 + 1 * 2 + 1* 3 + 1 * 4 + 2 * 1 + 2 * 2 + ... 4 * 4
exactly like a nested FOR loop?
Similarly, how can I multiply and sum only when first column value is bigger than second:
2 * 1 + 3 * 1 + 3 * 2 + 4 * 1 + 4 * 2 + 4 * 3 ?
With formula I think what is required, assuming A1:E1 and A1:A4 as shown, may be:
(1) The sum of B1:E4 where B2 copied across and down is:
=$A2*B$1
Alternatively the array formula with layout as you show:
=SUM(MMULT(A2:A5,TRANSPOSE(B2:B5)))
answer 100, and
(2) in B2 copied across and down and then B2:E4 summed:
=IF($A2>B$1,$A2*B$1,0)
answer 35.

Calculating total quantities

I have a situation where a bill of materials exported in the Excel pulls in the 'Level', 'Item' and 'Qty'. In order to calculate the total qty for an item in the BoM it is necessary to multiply up the quantities by the quantity in the parent levels. I have shown this below manually but due to the size of the real data set i was wondering if there is a method available using VBA to calculate the Total Qty values?
Level Item Qty Total Qty
1 A 1 1
1 B 2 2
2 C 3 6
2 D 1 2
2 E 2 4
3 F 5 20
3 G 3 12
2 H 2 4
3 I 1 4
2 J 1 2
2 K 3 6
1 L 2 2
1 M 1 1
Here is a UDF to use.
Paste it in a module in the workbook you are using.
Function qtyfind(level As Range) As Double
Dim i&, temp&, qtyClm&, tQtyClm&
'Change the Column name to match if different
qtyClm = WorksheetFunction.Match("QTY", Range("1:1"))
tQtyClm = WorksheetFunction.Match("TOTAL QTY", Range("1:1"))
If level = 1 Then
temp = Cells(level.Row, qtyClm)
Else
For i = level.Row To 2 Step -1 'loops bottom up
If Cells(i, level.Column) = (level.value - 1) Then
temp = Cells(i, tQtyClm) * Cells(level.Row, qtyClm)
Exit For
End If
Next
End If
qtyfind = temp
End Function
Then call it like this in the first cell and copy down:

How to force 4 digits in excel?

I have a really long truth table and the binary column is showing up like this:
A + B = S BINARY
0 + 0 = 0 0
0 + 1 = 1 1
0 + 2 = 2 10
0 + 3 = 3 11
0 + 4 = 4 100
0 + 5 = 5 101
0 + 6 = 6 110
0 + 7 = 7 111
0 + 8 = 8 1000
0 + 9 = 9 1001
0 + 10 = 10 1010
0 + 11 = 11 1011
0 + 12 = 12 1100
0 + 13 = 13 1101
0 + 14 = 14 1110
0 + 15 = 15 1111
Where the BINARY column =DEC2BIN(S)
I need to force the Binary values to have 4 digits all the time. So 0 = 0000, 3 = 0011, etc. How do I do this in excel?
Solution:
=DEC2BIN(S,6)
Rather than filling column S with:
=A1 + B1
to see 1 thru 15, use:
=DEC2BIN(A1+B1,4) to keep the leading zeros in 4-digit-binary format.
Highlight binary cells
Right-click, select "Format Cells..."
Number tab, select "Custom"
Enter 0000 into the Type text box.
Click OK.
Another, not the best way, but should work:
=RIGHT("0000"&DEC2BIN(S),4)
The above solution is correct
=DEC2BIN(A1,4)
This will show cell A1 in binary 4 digit format regardless of the value .
In the Spanish Excel version you use a semi colon like so .
=DEC.A.BIN(J6;7)

Resources