MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 20th, 2002, 10:27 PM   #1
chookers
Board Regular
 
Join Date: Mar 2002
Posts: 115
Default


Hello -

I'm using the following code to change the rowheight when info is entered. I'd like to get it to also add a top and bottom line to the row but I can't work out how to do it. Is it possible? I've put the usual Borders code in but I can't get it right.

Do I do something like EntireRow.Borders etc?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Range([A5], [A65536].End(xlUp)).EntireRow.RowHeight = 9

End Sub

I would also like it to merge columns C:L within each row but don't know if I'm pushng my luck.

Thanks for suggestions!

Chookers

chookers is offline   Reply With Quote
Old May 20th, 2002, 11:08 PM   #2
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi chookers, please try this


Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngLs As Long

'/// Delete all borders of Sheet
'/// If you do not need this, just delete following code line...
For lngLs = 5 To 12
Cells.Borders(lngLs).LineStyle = xlNone
Next

With Range([A5], [A65536].End(xlUp))
.EntireRow.RowHeight = 9
'/// [A5] add Borders
.Item(1).EntireRow.Borders(xlEdgeTop).LineStyle = xlContinuous
'/// [A???] add Borders
.Item(.Rows.Count).EntireRow.Borders(xlEdgeBottom).LineStyle = xlContinuous
'/// Merge Cells
Cells(Target.EntireRow.Row, 3).Resize(0, 8).Merge
End With
End Sub


HTH
__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Old May 21st, 2002, 12:00 AM   #3
chookers
Board Regular
 
Join Date: Mar 2002
Posts: 115
Default

Hi Colo - thank you - it almost works!

I can guarantee there will be at least one lame *** question from me in this but bear with me, I'm only beginning at this VBA thing - One of those dreaded scenarios where I'm great with Access so the boss thinks he'll give me an impossible (for me!) Excel task as surely they're all the same!!.

what has happend is it's changed the rowheight then I get an error message ' application or object defined error'. It hasn't put borders or merged cells yet. When I debug it goes to the last line - the Entire row.Cells...Merge line

To make matters worse I forgot that i can't put borders in column A so I'll change the code to accomodate that. What it will need to do is

Column B:L - underline top and bottom
Column D:L - merge cells within each row.

How can I tell it to only merge those columns of each row, and do you have any idea what it's not liking in that last line of code?

Thank you Colo!
chookers is offline   Reply With Quote
Old May 21st, 2002, 12:44 AM   #4
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Quote:
On 2002-05-20 23:00, chookers wrote:
Hi Colo - thank you - it almost works!

I can guarantee there will be at least one lame *** question from me in this but bear with me, I'm only beginning at this VBA thing - One of those dreaded scenarios where I'm great with Access so the boss thinks he'll give me an impossible (for me!) Excel task as surely they're all the same!!.

what has happend is it's changed the rowheight then I get an error message ' application or object defined error'. It hasn't put borders or merged cells yet. When I debug it goes to the last line - the Entire row.Cells...Merge line

To make matters worse I forgot that i can't put borders in column A so I'll change the code to accomodate that. What it will need to do is

Column B:L - underline top and bottom
Column D:L - merge cells within each row.

How can I tell it to only merge those columns of each row, and do you have any idea what it's not liking in that last line of code?

Thank you Colo!
Hi chookers, me again.

So, try this code.

First, try remove "0" of resize, so it will work.
Sorry I can not tell you why in English.
But on my system, it was work fine.(XL97-sr2,Win2K)


Private Sub Worksheet_Change(ByVal Target As Range)
'/// Delete all borders of Sheet
'/// If you do not need this, just delete following code line...
For lngLs = 5 To 12
Cells.Borders(lngLs).LineStyle = xlNone
Next

With Range([A5], [A65536].End(xlUp))
'/// Change RowHeight
.EntireRow.RowHeight = 9

'/// Column B:L - underline top and bottom
With Cells(.Item(1).EntireRow.Row, 2).Resize(, 11)
.Borders(xlEdgeTop).LineStyle = xlContinuous
End With
With Cells(.Item(.Rows.Count).EntireRow.Row, 2).Resize(, 11)
.Borders(xlEdgeBottom).LineStyle = xlContinuous
End With
End With
'/// Column D:L - merge cells within each row.
Cells(Target.EntireRow.Row, 4).Resize(, 9).Merge
End Sub





_________________
With regards,
Colo

[ This Message was edited by: Colo on 2002-05-21 00:24 ]
Colo is offline   Reply With Quote
Old May 21st, 2002, 08:54 PM   #5
chookers
Board Regular
 
Join Date: Mar 2002
Posts: 115
Default

Oh Colo Thank you so much for that, it worked really well. I was wondering if I could ask your advice on something.

What I'm using this for is a few people at work that would like to cut/paste some target outcomes from one worksheet to another (so that they can just have the target outcomes and not all the other stuff of the original worksheet) so they can write some notes in next to the outcomes on how they want to reach the goals (hence the merged cells). Now what will most likely happen is they will just copy all their target outcomes from one sheet and paste to the 'notes' sheet. Usually though this will involve pasting several rows, rather than just one.

I wanted to make it a bit easier for them so it would be easily formatted as you've done above, but even if they've pasted 4 rows at once.

Would I be better advised to do a macro that I could attach to a button, so they could use that and it would format all the rows (with the merged cells and lines etc)? From what I can gather the Worksheet change is mostly used for entering info a row at a time rather than if you have to paste several rows?

I know this is a long missive but I AM learning more about all code from this, not just this one, so thanks.

Kind regards,

Chookers



At the moment the worksheet has a header in A1:L4, these rows will never change, only ALL the ones below it. Basically the rows that would need to be changed are A5 through what ever the last row is. I am winding up using your code in another worksheet as well - as is.
chookers is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 10:47 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes