Excel/Repeating a formula in VBA
QUESTION: I have a column from A1 of numbers, say 1 to 11. I want to create a re-normalised list.
I write a formula in B1 "=A1/$B$6"
The vaue given is 0.16666
Now I copy the formula to cells B2 to B11 by dragging the corner of B1. I get a new column of numbers (last one is B11 = 1.83333
What is a simple way of writing a macro to wite the new list?
ANSWER: Sub Answer()
Range("B1:B" & Range("A10000").End(xlup).Row).FormulaR1C1="=rc[-1]/r6c2"
But manually or using VBA you're going to get a circular reference in cell B6 -- the formula in B6 will be =A6/$B$6.
---------- FOLLOW-UP ----------
Of course I made a mistake "=A1/$B$6" should have been "=A1/$A$6" giving r6c1 at the end of your formula.
I have figured out the rc notation form your example, but where can i find a reference to this? In Excel Help? What do I look up?
Also, can you explain how the Range("A10000").End(xlup).Row code works (it obviously gives the last row number of the table, but how) ?
In help, you can search for
and there's be many things to look at.
Range("A10000").end(xlup) is the code for effectively selecting cell A10000 and then pressing ctrl/Up-Arrow. The ".Row" part gives the row of effectively doing that. In reality, the cell is NOT selected and the ctrl/up-arrow "executed", but the effect is the same.
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here