PDA

View Full Version : active cell formula typing



inkara
03-25-2009, 04:35 AM
hi
i am very very new in VBA and like it very much
i have started using it 2 days ago
i am trying to understand the simplest syntaxis rules, and very confused many times:banghead:
my question is writing some formulas or different texts into a selected cell or range
i can not understand the difference between. both work same for me :(
can you please help me to understand. what is the purpose of R1C1 in first case, and what can be replaced there and what will change if we put smth else there

thanks in advance
1-

Cells(2, 2).Select
Selection.Activate
ActiveCell.FormulaR1C1 = "not inkara"

2 -
Cells(2, 2).Select
Selection.Activate
ActiveCell.Formula = "not inkara"

Zack Barresse
03-25-2009, 12:26 PM
Hi there, and welcome to the board!

First of all, you don't need to select a cell to do something with it. That is one of the first things you need to learn. This is done by almost every single beginner I've ever seen - including myself! You can shorten them to...


Cells(2, 2).Value = "not inkara"

A couple things to note.

1) I used Value instead of Formula or FormulaR1C1. If you're just putting a value into a cell(s), then that is all you need. If you're putting in a formula, then use the Formula property. There is also a FormulaLocal and FormulaR1C1Local. The best thing I can tell you is to look it up in the Help files, which are invaluable to a coder.

2) The basic differences between Formula and FormulaR1C1Local is the latter uses R1C1 style. If you look in the help files it should give an example of how they use it. You can use R1C1 reference style in a few different ways, both in a spreadsheet and in VBA. Basically it's a relative range which is based on the Row and Column.

3) No need to Activate anything. Activating a range is like when you select a range, then act on that range. The acting on the range is the activation, i.e. entering a value/formula, or right clicking it. In code you can just cut to the chase and enter the Value/Formula.

HTH

inkara
03-31-2009, 09:51 PM
Hi there, and welcome to the board!

First of all, you don't need to select a cell to do something with it. That is one of the first things you need to learn. This is done by almost every single beginner I've ever seen - including myself! You can shorten them to...


Cells(2, 2).Value = "not inkara"

A couple things to note.

1) I used Value instead of Formula or FormulaR1C1. If you're just putting a value into a cell(s), then that is all you need. If you're putting in a formula, then use the Formula property. There is also a FormulaLocal and FormulaR1C1Local. The best thing I can tell you is to look it up in the Help files, which are invaluable to a coder.

2) The basic differences between Formula and FormulaR1C1Local is the latter uses R1C1 style. If you look in the help files it should give an example of how they use it. You can use R1C1 reference style in a few different ways, both in a spreadsheet and in VBA. Basically it's a relative range which is based on the Row and Column.

3) No need to Activate anything. Activating a range is like when you select a range, then act on that range. The acting on the range is the activation, i.e. entering a value/formula, or right clicking it. In code you can just cut to the chase and enter the Value/Formula.

HTH

inkara
03-31-2009, 10:00 PM
thanks a lot for your quick reply and help

Zack Barresse
04-03-2009, 12:25 PM
You're very welcome. If this solves if for you, please mark it as such from the Thread Tools | Mark Thread Solved | Perform Action. :)