I have a large range (upto 60k lines) which I would like to apply a formula too.
A loop would take too long. The formula would apply to info on the row so wouldn't be the same exactly but the row would be the only variable.
What's the best way to do this? I thought I would use VBA rather than Excel to make sure the spreadsheet didn't get too cumbersome.
Below is a simple way to do what you want. If the formula takes too long to update it may be better to calc the result using VBA and output the result to the range.
Assume you want the formula =INDEX($M:$M,MATCH(A2,$N:$N,0),0) in rows D2:D60000
i. Turn on the macro recorder
ii. Enable Use Relative References
iii. Enter the formula required in a single cell (ensure if dragged down it will be correct for all rows)
iv. Turn off the macro recorder
v. In the VB Editor find the formula recorded - eg
ActiveCell.FormulaR1C1 = "=INDEX(C13,MATCH(RC[-5],C14,0),0)"
vi. Apply the formula to the required range using
Sheet1.range("D2:D60000").FormulaR1C1 = "=INDEX(C13,MATCH(RC[-5],C14,0),0)"
Related
Im trying to write a VBA code for which will fill my excel SUMIFS formulas.
In general SUMIFS will calculate sums based on other workbook data.
Other workbook filename is currently hardcoded in my macro, however i'd like to make it more flexible and instead of hard coding it i'd like to use a cell in which i put the file name.
so far macro creates the following formula and puts it in cell:
=SUMIFS([SW.xlsx]TeamAllocations!F$9:F$401,[SW.xlsx]TeamAllocations!$D$9:$D$401,$D16,[SW.xlsx]TeamAllocations!$B$9:$B$401,$B16)
what i'd like to have is kind of:
=SUMIFS([<variable evaluated based on a cell which has filename/filepath, eg B1>]TeamAllocations!F$9:F$401,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$D$9:$D$401,$D16,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$B$9:$B$401,$B16)
So in B1 cell i'd have "SW_01.xlsx" or "SW_02.xlsx", so the SUMIFS formula will always have up-to-date soruce.
Is that possible in excel?
Thanks
J.
If all your files have a fixed format, I think you can combine all of the files with power query.
You can do what you want more easily.
Combine Files:
https://chandoo.org/wp/combine-excel-files-using-power-query/
Group in PowerQuery (same as SUMIF):
https://support.office.com/en-us/article/group-rows-in-a-table-power-query-e1b9e916-6fcc-40bf-a6e8-ef928240adf1
Useful filter:
https://exceleratorbi.com.au/pass-excel-parameter-power-query/
Im working with a large excel questionnaire that i would like to simplify the data output for further evaluation.
What I'm trying to make is an IF statement, so that if the X is in fueloil the P coloum will write Fueloil ect..
=IF(K2="X";K1)
However when I'm trying to add another IF statement excel returns VALUE. is IF the right way to go about this or is there another way of doing this?
You don't need IF for this at all. You can use an Index/Match combo formula as demonstrated in the screenshot below. The formula in cell P2 is copied down.
=INDEX($K$1:$O$1,MATCH("x",K2:O2,0))
In words: Find the "x" in the current row and return the value from row 1 of that column.
If your regional settings require semicolons to separate parameters in formulas, please use
=INDEX($K$1:$O$1;MATCH("x";K2:O2;0))
I have few formulas in a row and I want to drag them down. Formulas are complex and I don't have them in R1C1 format and I don't want to convert them into R1C1, but I would like to do something like:
Range(A2:B10).Formula = Range.(A1:B1).Formula
I know this would put the same formula into the whole range, I need a "drag effect" - so it's changes relatively to each row but without copy-pasting.
P.S. I don't want to copy-paste, as it eats more CPU, I'd like to have something
Define the range that you want to fill with the formula and use Range.FillDown.
Range("A1:B10").FillDown
Note: The first Row(s) of the range must include the original formulas
A tiny trick !:
Sub KopyFormulas()
Range("A1:B1").Copy Range("A2:B10")
End Sub
will copy the formulas downward and adjust them as well !
For single cells, you don't need to explicitly convert formulas to R1C1 format to use FormulaR1C1.
Even if you are using the standard A1 style of referencing, you can still use
Range("B2:B10").FormulaR1C1 = Range("B1").FormulaR1C1
And this will have the effect of copying down the formula in B1. It doesn't change the default format -- they will still display in the A1 format.
There does seem to be an issue with doing this with a block of two or more cells. You could do it column by column (in a loop if desired):
Range("A2:A10").FormulaR1C1 = Range("A1").FormulaR1C1
Range("B2:B10").FormulaR1C1 = Range("B1").FormulaR1C1
Whether or not this is worth the hassle (compared to the simple .FillDown) is another question. You could time it.
By the way -- I wouldn't think that .FillDown is particularly inefficient. Did you do the usual optimizations of turning off of screen-updating, setting calculation to manual, etc.?
I wrote this simple formula in an Excel sheet.
=CONCATENATE(A$1,"='",A49,"', ",B$1,"='",B49,"', ",
C$1,"='",C49,"',",D$1,"='",D49,"'")
It combines the cell value of the current row with the column headers.
I put it on E49 and if I copy-paste it anywhere in column E it adjusts nicely. I want to improve it and make it more generic and I'd rather not use VBA to keep it simple (i.e. install on any spreadsheet with simple copy paste of cell formula.)
FEATURE DONE:
Automatically adjust to change the label in column headers.
FEATURE MISSING:
Adjust to add/remove columns by editing a few characters (e.g. having a "A:D" or "A1:D1" argument in the formula. )
Automatically adjust to add/remove columns.
QUESTION:
Can I do that with a formula only? If not, is there any formula that could get close to the same result?
it depends on how complex you want the formula to be. I think its a less elegant solution, but you could theoretically build a huge IF(..) statement to test if column names exist.
IF they are not blank, perform the concat.
personally, I would use VBA, and toss it into an Add-in; that way it would open within any instance of excel on the local computer.
I've been trying to get to grips with excel formulae for days, and now have a spreadsheet with 140 cells, each with a slightly different formula. Unfortunately, it now needs to be 'dumbed down' to Excel 2003.
I've tried to get my head round array formulae, and SUMPRODUCT, but I'm getting bogged down.
Fresh eyes, anyone?
This is the formula I need to convert from 2010 to 2003:
=AVERAGEIFS(Data!S:S,Data!L:L,"Atherstone",Data!T:T,"Service",Data!C:C,">="&K3,Data!C:C,"<="&K4)
K3 is a date range start, with K4 being the end, and Data! refers to Sheet 2 where all the data is held.
(I know all my cell ranges will have to be explicit - i.e. C2:c65536).
You will need to specify your range as a fixed area, as it will not understand S:S.
your formula will end up looking something like this:
=AVERAGE(IF(Data!L2:L2000="Atherstone",IF(Data!T2:T2000="Service",IF(Data!C2:C2000>=K3,IF(Data!C2:C2000<=K4,Data!S2:S2000)))))
(Untested)
you will also need to make it an Array formula, so excel can look at each of the values in the range individually by entering the formula using CTRL+SHIFT+Enter, instead of the more usual Enter after you have finished typing everything