AusSteelMan
Board Regular
- Joined
- Sep 4, 2009
- Messages
- 208
Hi everyone,
I have a question about the .Formula command. I have a macro which works correctly, so my question is actually about my understanding/learning and cleaning my code up: not making the code work.
Quick scene-setting:
I have a long formula that concatenates several pieces of text from a range of cells. If the user wants to insert a row into the worksheet, they run a marco. This macro ensures all the formulas are inserted cleanly in the right places.
For simplicity, I have shortened 1 of these forumla build codes.
IRN= the row number of the active cell
So this code inserts a formula into the 12th column (column L) and row IRN
If I use the .Formula syntax, I can get it to work if it looks like this:
Basically just added ".Formula"
Questions:
1. Is one method preferred over another and/or are there downfalls of one over the other?
2. Is there a "cleaner" way of writing the .Formula version? I don't know how to incorperate the IRN without concatenating string of text. Any examples I've seen look something like
which could easily have the IRN used to determine the cell location as such:
but I don't know how else, if possible, to include IRN into the actual formula.
Like I said above, this is only for my knowledge and in an attempt to clean up code.
Any thoughts are greatly appreciated.
Thanks,
Darren
I have a question about the .Formula command. I have a macro which works correctly, so my question is actually about my understanding/learning and cleaning my code up: not making the code work.
Quick scene-setting:
I have a long formula that concatenates several pieces of text from a range of cells. If the user wants to insert a row into the worksheet, they run a marco. This macro ensures all the formulas are inserted cleanly in the right places.
For simplicity, I have shortened 1 of these forumla build codes.
Code:
Cells(IRN, 12) = "=BA" & IRN & "&$BG$2&BB" & IRN
So this code inserts a formula into the 12th column (column L) and row IRN
If I use the .Formula syntax, I can get it to work if it looks like this:
Code:
Cells(IRN, 12).Formula = "=BA" & IRN & "&$BG$2&BB" & IRN
Questions:
1. Is one method preferred over another and/or are there downfalls of one over the other?
2. Is there a "cleaner" way of writing the .Formula version? I don't know how to incorperate the IRN without concatenating string of text. Any examples I've seen look something like
Code:
[FONT=WileyCode-Regular][SIZE=2][FONT=WileyCode-Regular][SIZE=2]Range(“A13”).Formula = “=SUM(A1:A12)”[/SIZE][/FONT][/SIZE][/FONT]
Code:
[FONT=WileyCode-Regular][SIZE=2][FONT=WileyCode-Regular][SIZE=2]Cells(IRN, 12).Formula = “=SUM(A1:A12)”[/SIZE][/FONT][/SIZE][/FONT]
Like I said above, this is only for my knowledge and in an attempt to clean up code.
Any thoughts are greatly appreciated.
Thanks,
Darren