How to modify excel autofill? - vba

I have got a timetable. I want to transpose data in rows to column (rather using formulas) in the way which is shown on this picture.
In first row (AU,KM,GK,MZ) are teachers, in second one are rooms.
In B23 cell is formula: "=INDIRECT(ADDRESS(COLUMN(Q2),ROW(Q2)))"
in B24 "=INDIRECT(ADDRESS(COLUMN(R2),ROW(R2)))",
in B25 "=INDIRECT(ADDRESS(COLUMN(Q3),ROW(Q3)))",
in B26"=INDIRECT(ADDRESS(COLUMN(R3),ROW(R3)))"
I want to fill monday column, but excell autofill is not working like i would like - next formulas are for example q5,r5,q7,r7,q9,r9 instead of simple increasing this way -> q1,r1,q2,r2,q3,r3,q4,r4,q5,r5 etc.
How to fix it? Any help will be appriciated.

In B13:
=IFERROR(INDEX($7:$7,MATCH(A13,$5:$5,0)),"")
In B14:
=IFERROR(INDEX($8:$8,MATCH(A13,$5:$5,0)),"")
Then copy and fill both down.

Related

Autofill but skipping a column

My current formula is:
=IF(COUNTIF('W/C 1/8/22'!B$47:C$53,""&$B12&""),"S1","-")
When dragging/autofilling I would like the next box to refer to columns 'D'&'E'(and then the following 'F'&'G') and so on, basically to skip along as I have merged two columns on the 'w/c' sheet.
D11 is the first box this formula will be in and hopefully will be able to drag
/autofill from there.
I have tried lots of different methods but can't seem to insert the correct formula to make it work. Any help would be most appreciated, thank you!

The range in the Excel formula changes after insert-shift, how can I stop it changing?

I have an Excel 2010 formula in an Excel cell like this (the formula lies in column T):
=SUMIF($B$14:$B$44335;$T8;$E$14:$E$44335)
This formula does this: It finds the cells in the Range("B14:B44335") which have the value as Range("T8") (For example, between Range("B192:B370")), then it sums up the values in the column E (For example, sums up between Range("E192:E370")).
The formula works fine, but a background VBA-code couses problem. This VBA code sometimes extends or shorten Range("B14:E44335"). The VBA-code uses insert shift:=xlDown or delete shift:=xlUp for extending or shortening.
Insert shifting (inserting 178 rows) in VBA causes that the formula changes like this:
=SUMIF($B$192:$B$43623;$T8;$E$192:$E$43623)
So the formula also shifts from B14 to B192.
This is strange, because the formula is in the column T, and the VBA-code has nothing to do with the column T.
I tried to give a name to the range like, when I write Countries, then Excel selects the Range("B14:E44335"), so
=SUMIF(Countries;$T8;$E$14:$E$44335)
But i got the same problem again. After Insert Shift, Countries shows Range(B192:B43623")
In anyway, how can I keep the range in my formula permanent, no matter what happens in other cells?
try this:
=SUMIF(offset($b$1,13,0,44321, 1), $t8, offset($e$1,13,0,44321))
This uses OFFSET to create the fixed range: 14 to 44335 .. if that should be a fixed range, you should be golden.
If not, you need to figure out some formula/logic to calculate the 13 and the 44321 .. ;)
For reasons mentioned by Scott in comments above, Excel is adjusting your ranges, offset bypasses that ;)

Lookup function in multiple sheets data

I have multiple sheets of data and I want to make it in one sheet (All of them are in the same workbook). Link to the excel file.
I tried to use Hlookup function in excel file, something like below:
=HLOOKUP("University",Sheet1!$A$1:$G$2, 2, FALSE).
But, since I have more than 100 sheets of data, I want to find a way to drag the function and auto generate the function below the 2nd row. I have tried to use indirect function by setting a reference column in front as below but cannot deal with it.
=HLOOKUP("University", 'INDIRECT(A3)'!$A$1:$G$2, 2, FALSE)
My next option is VB code. But, I am new to VB. Anybody can help on it?
Place your individual sheet names in column H of the Summary sheet and the row number in column I (as helper columns) and write this formula in cell A2 of the summary sheet.
=IFERROR(HLOOKUP(A$1,INDIRECT($H2&"!A1:G"&$I2),$I2,0),)
and drag to column F and down for as many sheet rows combos you have. I used 10 rows but you can obviously make it longer or shorter as neeed.
When you are done you can filter on 0 in column A and remove any lines with no data.
If your sheet names have spaces in them, you'll need to adjust the INDIRECT formula to this:
INDIRECT("'"&$H2&"'!A1:G"&$I2)
best way would be "defined names" + INDIRECT + HLOOKUP (or LOOKUP) like:
defined names
name: SList
formula: =MID(TRANSPOSE(GET.WORKBOOK(1))&T(NOW()),FIND("]",TRANSPOSE(GET.WORKBOOK(1))&T(NOW()))+1,255)
formula in cells: (this in A2 then simply autofill to G2 and thenn everything down) (you'll get a row with 0's between the sheets, which can be filtered out or deleted later (copy/paste values))
=IFERROR(HLOOKUP(A$1,INDIRECT("'"&INDEX(SList,COUNTIF($A$1:$A1,0)+2)&"'!$A:$G"),$H2,0),"")
Set H2 to 2 and for H3: (autofill down from H3)
=MAX(($H2+1)*($A2>0),2)
works perfectly for me LINK
No manual typing of sheetnames or something like that (only Column H:H as helper). Youll get rows's with 0's every time a new sheet is selected which can be filtered out. (or if you copy/paste values also can be deleted)
the +2 at ...st,COUNTIF($A$1:$A1,0)+2)&... simply tells to start with sheet 2 (if summary is the first). You may change it to +1 if you want to lookup starting with the first sheet.
Assuming you already have all 100+ sheet names typed out in column A, this will work whether or not you have spaces in the sheet names:
=HLOOKUP("University", OFFSET(INDIRECT(ADDRESS(1,1,1,1,A2)),0,0,2,7),2,FALSE)

How to do a summation only within specific cells via VBA

In reference to the picture below, I would like to loop through a certain column (Column D in this case) until I hit a specific cell (Yellow cells in this case). In my final spreadsheet I have multiple yellow cells that I would like to target. Once I hit a yellow cell, I would like to start a simple summation of the values one cell to the left of the yellow (Column C). I would like to keep summing the values until I hit a blank cell, which would indicate the end of the set.
Please let me know if you need any more clarification!
Here's some code that should get the job done. However you are going to have to adapt it to however you want to use it.
Dim Summation as Double
For Each Target in Range("D:D")
If Target.Interior.ColorValue = 6 Then
Summation = Summation + Target.Offset(0, -1).Value
End If
Next Target
I hope this helps. However, don't forget about FreeMan's suggestions about good question asking and using the macro recorder!

Excel Cell reference that will go to the left

I am using an excel spreadsheet formula to add two cells together and I want to have it reference one row from left to right like it normally does, but I need it to reference the same row in another page in reverse, and then be able to drag the formula through the entire worksheet. I cannot seem to find anything like this when I look online. TLDR I need to know how to tell excel reference the cell to the left if I drag it to the right.
so I need to add A0 in page one and A9 in page two then when I copy the formula to the left I need it to grab A1 and A8, is there a way to get this?
Your question is not very clear; for example, you talk about a formula but have an Excel-VBA tag. However, I think I understand the effect you seek.
I have filled A1:I1 of the current sheet and A1:I1 of worksheet “Sheet3” with numbers.
I have typed the following formula into another cell within the current worksheet:
=A1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(A1))
The target area for the INDEX function is Sheet3!$A$1:$I$1. This is a one row range so I do not need a row number. The column number is 10-COLUMN(A1) which is 9 so this formula is equivalent to:
=A1+Sheet3!I9
If I copy the formula one cell to the right I get:
=B1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(B1))
This is the equivalent of:
=B1+Sheet3!H9
You can continue copying the formula to the right until you get:
=I1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(I1))
Attempting to copy further gives an error because 10-COLUMN(J1) is zero and there is no column 0.
There are other methods of achieving this effect. The key feature of any such method is the expression N-X where N is a constant and X gets bigger as the formula is copied further to the right.