Need VB code to add a formatted line

darkelf26

New Member
Joined
Oct 5, 2006
Messages
37
Hi,

I have a worksheet with 4 tables on it.

Under each table I have several clickbuttons. What I would like is one of those buttons to add a line to the table it is under and format specific cells in it in a specific way.

I can do the scripting for the formatting and adding a line but to not to select the cells within the newly added row so that they can be formatted.

Can anyone help please.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the Board!

Can you identify/select the newly added row?

If not, please explain the logic for how this row is selected.

If so, you can use one of the following methods:

1. If you know which column you are starting in in your new row, you can OFFSET, i.e. IF you start in column "A" and want to put something in column "E", use:
ActiveCell.Offset(0,4)=...

2. If you only know the row, but not the current position, you can use something like:
Cells(ActiveCell.Row,"E")=...
 
Upvote 0
The tables are all in the same sheet so the row numbers can change if a row is added to any of the previous tables.

Also the formatting I want to do is to merge 5 cells so would the command be:

Cells(ActiveCell.Row, "D:I").Select
 
Upvote 0
Hello darkelf26, welcome to the board.
. . .the formatting I want to do is to merge 5 cells so would the command be:
Cells(ActiveCell.Row, "D:I").Select
I don't see Joe around so I'll throw in my two cents worth.
First off it is generally felt among 'coders' that "merged cells is the devil" and they are for the
most part avoided if at all possible.

That being said, if you still need to merge them you don't have to select them to do it. (You
very seldom have to actually select an object in your code to work with it.)
To merge the cells in columns D:I of the active row you can use this.
Code:
Range(Cells(ActiveCell.Row, "D"), Cells(ActiveCell.Row, "I")).Merge
 
Upvote 0
"merged cells is the devil"
Absolutely! The "Center Across Selection" is usually the much better option, as it gives you the same visual effect without all the problems that merged cells cause.

(Thanks for the pickup HalfAce, I have been busy and have only here intermittenly today).
 
Upvote 0
Yeah, without a doubt Center Across Selection is preferred over actual merging.
I guess you'll have to download ASAP Utilities to get it though.
I thought we had that option in XL '03 but I can't find it now (and certainly can't find it
in XL 2K).
 
Upvote 0
I didn't even know there was a toolbar button, I always did it the way that Boller referenced. That doesn't require ASAP utilities.
 
Upvote 0
HA! I was pretty sure I'd seen it somewhere!
Just didn't look far enough in the format cells options. - (And we even have it in XL 2K!) Cool.

Thanks Boller. :cool:
 
Upvote 0
thanks guys, thecentre across coloumns has solved this issue and one I was having with the fact that you cant merge cells in a shared workbook.
 
Upvote 0

Forum statistics

Threads
1,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top