Excel 2010 VBA Autofill entire column - excel

I am having trouble getting VBA to do the equivalent of Autofilling an entire row (such as when you double click on the plus sign of a cell with a formula and it autofills the appropriate number of columns).
Along Column A I have a list of dates. Along Row 3 I have a list of formulas. How do I write a macro which will effectively do this:
For i = 2 to Columns.Count
'FillDown the whole of Column i with the formula in Cells(3,i)
Next i
I want the fill down, not just a copy of the exact formula... Does anyone know how this can be done? I've got a method which is taking about 20 minutes so far but when I do this process manually it takes not very much time at all, so I think there must be a much faster way.
Thanks very much in advance for your help!

You can try to use Autofill with a destination range.
Something like:
Selection.AutoFill Destination:=Range("A2:A12")
[EDIT] Or:
Range("A1").AutoFill Destination:=Range(Cells(1, firstColNumber), Cells(1, lastColNumber))

Related

Excel Nested Conditional If Formula with Binary 0 or 1 Output

I am trying to use a multi-nested conditional Excel formula properly. I think what I have is close but I'm missing something.
=IF(BF6=1,IF(AI6=AI9,IF(BC8=0, 0,1)))
I am not sure I can use AI6=AI9 to specify that the contents of these cells are identical.
Separately, I want this formula to repeat every 7 rows, so I expanded the formula to include the this function:
=IF(MOD(ROW()-1,7),"",IF(BF6=1,IF(AI6=AI9,IF(BC8=0, 0,1)))
Any advice would be appreciated.
Screenshot of problem with new formula: =IF(AND(EXACT(AI6,AI9),BF6=1,BC8=0),1,0)
Image of final formulas that work
In the end, I had to use two formulas in two consecutive cells to make it calculate correctly.
=IF(EXACT(AI6,AI9), 1,0)
=IF((AND(BB9=1, BF6=1, BF9=0)), 1, 0)
I will conquer using IF, AND and EXACT in one conditional formula some other time. Thanks for all the help!
REVISED:
From what I understand, this is what you want. Copy the following formula and paste on cell BB9 then drag the formula down to where the record ends.
=IF(MOD(ROW()-2,7),"",IF(AND(AI6=AI9,BH6=1,BH9=0),1,0))
MOD(ROW()-2,7) is to determine where the result should show. Row() means the current row, and I subtract 2 to eliminate header row and blank row on row 2. 7 is to repeat every 7 rows.

Formula for a range of numbers equals a number in a cell on a different sheet

I am looking to do a formula in Excel to say a cell has a number inputted for example between 500-999 and it picks up a cost from a cell on another sheet.
so far I can only get 2 ranges to work using:
=If(C2<=999,Sheet1!H3,IF(C2>=1000,Sheet1!H4))
But if I do:
=If(C2<=999,Sheet1!H3,IF(C2>=1000,Sheet1!H4,IF(C2>=2000,Sheet1!H5)))
It still takes the value for >=1000
Any help on this will be grately appreicated.
Change the places of the conditions for 1000 and 2000. Like this:
=If(C2<=999,Sheet1!H3,IF(C2>=2000,Sheet1!H5,IF(C2>=1000,Sheet1!H4)))
In general, F9 can do a wonderful job, when you are working with Excel formulas.

Excel automagically insert formula

I came across this excel files (xlsx) so there is no VBA involved, no table, no name. But columns C is updated with formula "automagically" when I insert a number into column B. I checked the name manager, there is no name. I would like to know how can I achieve this kind of functionality. Have anyone come across something like this?
P.S: When I copy Range A2:C13 and paste to a different files. The magic still works!
Screenshot in Excel 2016
So, you go to File>Options>Advanced and tick the box that says:
Extend data range formats and formulĖ˛as
Ok, I got this one. Simply add 4 or 5 subsequence row with formula in column B and C. And continue continue to enter data in column B like this GIF:
I manage to have this behavior by having the formula defined on all the cells of the column* with an "IF(NOT(ISBLANK(c); <your formula>; "")" condition on the input cell:
e.g. you enter this in C1
=IF(NOT(ISBLANK(B1)); B1/(1+B1);"")
you click and drag the formula like you know how;
Et voila
*)(or as many as necessary, since it could be a little "heavy" for Excel to have the formula 1048576 times, nearly for nothing)
Hope it helps

Excel sum range & next set of range numbers

Trying to do something which I think is quite easy but I cant figure it out.
I have a row of about 1000 items. I want to sum for items (A1:H1) and then (I1:Q1) and so on until I get to the end. When I try to do (A1:H1) and drag the formula button across it then gives me (B1:I1). Im trying to avoid this.
Thanks!
Slightly convoluted but the below should work for you. You will need to add in the names of your sheet instead of "Sheet1", it essentially works off of the column reference of the cell the formula is placed into, I had it starting in column A.
=SUM(INDIRECT("'Sheet1'!"&ADDRESS(1,(((COLUMN()-1)*8)+1))&":"&ADDRESS(1,(COLUMN()*8),1,1)))

Apply formula to large range

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)"

Resources