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 Apr 9th, 2002, 02:54 PM   #1
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

I want automatically to hide rows that contain no data just before printing.
A cell in the row to be hidden in Sheet 2 contains the formula: =IF(Sheet1!A15=0,"",Sheet1!A15) so we need to look at the result and not that the cell contains nothing. Users will enter figures on Sheet 1 which are then formatted and totalled on Sheet 2.
If cells A15 and A16 on Sheet 1 are left blank, I want the corresponding rows (not necessarily rows 15 and 16) in Sheet 2 to reduce to zero width.
I think I need a macro with a series of If Then operations but have been struggling with my very basic knowledge of VBA.
Users might need to go back later and put information in A15 or A16 or both so the macro would have to unhide (and preferably autofit the relevant rows in Sheet 2) when run again. I would also like to restore normal row heights to the rows on Sheet 2 on exit from the worksheet.
inarbeth is offline   Reply With Quote
Old Apr 9th, 2002, 03:04 PM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
I don't know what the corresponding rows are?
I would put a simple macro in the Workbook_BeforePrint event or Worksheet_Change on sheet1 which would hide the rows. Then restore the rows in the Worksheet_Change on sheet1, testing for an added value in A1.
How do you know which rows to hide???
Maybe you could change your formula to:
=IF(Sheet1!A15=0,"HideRow",Sheet1!A15)
Which columns contains these formulas?
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 06:10 AM   #3
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

The corresponding rows are the ones left blank on Sheet 2 if A15 and A16 are empty but which will contain the contents of cell A15 and cell A16 on sheet 1 otherwise. The reference to corresponding rows was so that the macro can select which rows to hide. If someone can kindly give me the basic code, I should be able to edit it to hide the relevant rows on Sheet 2.
inarbeth is offline   Reply With Quote
Old Apr 10th, 2002, 06:28 AM   #4
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

'To hide rows 6 & 7
Rows("6:7").EntireRow.Hidden = True
'To hide row 6 only
Rows("6:6").EntireRow.Hidden = True

Change the true to false to unhide
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 06:33 AM   #5
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

Thank you Tom. I may not be making myself clear. I need the If Then bit as well and presumably an If Then to unhide on a repeat pass if figures are later put in cells A15 and A16.
inarbeth is offline   Reply With Quote
Old Apr 10th, 2002, 06:42 AM   #6
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

No you are not making yourself clear...
If then what?
There are 256 cells in one row.
Which column(s) intersecting the rows in question holds the determining value.
If A5, B5, C5 = "" then hiderow?
How many rows deep? 65536?
Please give more detail...
Thanks,
Tom


Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 07:03 AM   #7
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

Sorry,
For the sake of the example, Cell B18 on Sheet 2 will contain the formula =Sheet1!A15. Cell B20 on Sheet 2 will contain the formula =Sheet1!A16. If cell A15 on Sheet 1 is empty then hide Row 18 on Sheet 2. If cell A16 on Sheet 1 is empty then hide Row 20 on Sheet 2.

The user might go back to Sheet 1 from Sheet 2 and add data to A15 and/or A16. If the user is undecided he or she might go back again and clear the cells again.

So on re-running the macro, if cell A15 on Sheet 1 is not empty then autosize Row 18 on Sheet 2. If cell A16 on Sheet 1 is not empty then autosize Row 20 on Sheet 2.

I will attach the macro to a button taking the user from Sheet 1 to Sheet 2. Therefore the macro will run each time and needs to test whether cells A15 or A16 are empty or not. The user will see that rows 18 and 20 on Sheet 2 will be hidden or unhidden depending on whether anything has been put in A15 and A16 on Sheet 1.
inarbeth is offline   Reply With Quote
Old Apr 10th, 2002, 10:25 AM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Gotcha!
I hope

Sub RowStuff()
Dim RowCntr As Long
For RowCntr = 1 To 1000 'or increase number of rows if necc.
If Sheet2.Range("B" & RowCntr).Value = "" Then
'if the value of B? = "" then hide row
Sheet2.Rows(RowCntr & ":" & RowCntr).EntireRow.Hidden = True
Else
'if the value of B? <> "" then un-hide & autofit row
Sheet2.Rows(RowCntr & ":" & RowCntr).EntireRow.Hidden = False
Sheet2.Rows(RowCntr & ":" & RowCntr).EntireRow.AutoFit
'if you would rather set to a predetermined row height use:
'Sheet2.Rows(RowCntr & ":" & RowCntr).RowHeight = 7.5
End If
Next
End Sub

Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 03:18 PM   #9
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

Thank you for all the time you are taking but we are not quite there yet. I don't want to hide all rows except those corresponding to rows in Sheet 1 with stuff in them. I want to hide only the single rows concerned. Thus if there is nothing in A15 in Sheet 1, row 18 in Sheet 2 (but no others) will be hidden. I gave the example of two rows because I might wish to make it 3 or 4 and the code may be different from that for just a single row.
I am hiding the rows so that when Sheet 2 is printed I avoid what would otherwise be acres of blank space. Thanks
inarbeth is offline   Reply With Quote
Old Apr 13th, 2002, 02:46 AM   #10
inarbeth
Board Regular
 
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
Default

Playing around with your code (and with a bit of help from the macro recorder) I have come up with the following code:

Sub RowStuff()
If Sheet1.Range("A15").Value = "" Then
Sheet2.Rows("18:18").EntireRow.Hidden = True
Else
Sheet2.Rows("18:18").EntireRow.Hidden = False
Sheet2.Rows("18:18").EntireRow.AutoFit

End If

End Sub

How do I get it to repeat to hide other rows, eg if A16 is empty to hide Row 20 on sheet 2? I expect the answer is very simple.
inarbeth 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 12:27 PM.


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