Re: VBA Inserting columns and keeping formulas in Table Ranges
Hi Prisch,
...Well done... Thank you for you this. .....
Yous welcome. Thanks for the feedback
_............
... I was not expecting it to be so extensive. ...
-.. as i mentioned the final code can be simplified greatly.....
_...................................
....
Inserting more than one row/column at once causes run-time error. I'm guessing this is caused when there is no values to clear. .....
Correct ! How dopey of me. Exactly what you say.
You could just ignore it, as it effects nothing as it errors at the end, but i can do a quick mod to overcome that, no problem.
_.............................
.....
The row inserted replaces any data below the expense table instead of shifting it down. Eg. A row showing profit for the month (Total sales - Total expenses) .....
I think i follow what you are saying there. That is a little bit to do with what i meant
here
........
....
So these two codes I got basically by running a macro recorder , then tweaked them a bit. (Note I am inserting whole columns and rows here, ( which i changed in my final code to just inserting specific Ranges) - . Depending on how you may be adding things to the sheet, one way or the other may be better.
_ - But concentrating on a specific Range would make it an interesting exercise to compare with a ...
........
In addition to that, which way to do it that is the best will depend on what / if / where other stuff is in the Spreadsheet, which is why I asked if you would be adding later . I maybe stupidly assumed you had nothing immediately below the table as the last bit, sorry about that.
The problem is probably because section
Rem 5)
Effectively chops that last row out. ( i think )
Depending on exactly how your data looks, removing that section, Rem 5) may be sufficient to overcome that problem.
But it might be better to redo the code to insert entire columns and rows, rather than just those in the Tables....
Again I see no problem there. Just a case of how i am inserting things, and how that effects you.
BTW: On that Inserting point: - I often learn from answering these threads. Getting good at Inserting things in different / controllable ways is what i seem to be learning from this thread... –Yesterday my spreading apart to insert things knocked me a bit off wack, and i got it wrong at first.
I need ( or would like ) to get that clear in my mind. I am going to do some Test now over at the Test Area to get that clear in my head. I want to sort that out for myself first.
Test Here
http://www.mrexcel.com/forum/test-here/936964-test-inserting-things-properly.html
If you have the time in the meantime, you can post some more screen shots showing, for example where things like your row showing profit for the month (Total sales - Total expenses) is. Keep the data to a minimum, like you did, that is better, ( even knock out another column or row or two )
If you had time to install and use the Forum Tools to do that and practice that for some screen shots that would be great in the long run. ( Play around testing and experimenting here in the Test Area if you do that..
_.. if you feel the erge You can stick stuff in my Thread there, or just start one of your own.... you can do anything there in the Test Area, – the threads are mostly ignored then deleted after a few days..
..)
I know that is all a pain initially, but well worth it in the long run to get help at MrExcel.
BTW. I did an alternative to an Add-In just now, for someone who was having problems with installing an Add-In.. What i have done is posted a simple code done by another member, Marcelo Branco, that does the same to get a screen shot to paste in a Forum Thread. Maybe worth a quick look, if you have the time.
http://www.mrexcel.com/forum/test-here/936964-test-inserting-things-properly.html#post4501034
http://www.mrexcel.com/forum/test-here/936964-test-inserting-things-properly.html#post4501015
_...............................................
.......The total column does not maintain its number format.......
I am not too clever with number formats. Especially as our different settings may influence things. I was ( am ) hoping the key to that was using the
_ Range. PasteSpecial
Stuff.. ... But if I have time I will look at that as well
_.................................................
So i will try to post back again, maybe a bit later after i have played around a bit. If in the meantime you can do some more screenshots that would be good. Or alternatively upload another file. But i think i get the jist of what is needed anyway.
Try to catch you later.
Alan