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, 03:44 PM   #1
kls
Board Regular
 
Join Date: May 2002
Posts: 69
Default

I have checkboxes on Sheet 1 that populates Sheet 2; if the checkbox = true. Depending on the “text” of A5 on Sheet 2, then a listbox will populate cell D5 on Sheet 2.

The VB Code I'm using is:

If CheckBox9.Value = True Then
Worksheets("Sheet2").Range("A5").Value = "Air Emissions"
Worksheets("Sheet2").Range("B5").Value = "Point Source Air Emission"
Worksheets("Sheet2").Range("C5").Value = "CO2"
Else
Worksheets("Sheet2").Range("B5").ClearContents
End If
If Worksheets("Sheet2").Range("A5").Value = "Air Emissions" Then
Worksheets("Sheet2").Range("D5:D5").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=AirEmissionsI"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End
End If
End Sub

The Code bombs at [Worksheets("Sheet2").Range("D5:D6").Select]. How do I state that I want to Select Sheet2, Range D5 without activating the sheet?

kls is offline   Reply With Quote
Old May 20th, 2002, 04:32 PM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

The following tends to be a little hardier than select:


Application.Goto Sheets("sheet2").[d5:d6]


But you could define the area and work with it without selecting:


Sub redo()
Dim n As Range
Set n = Sheets("sheet2").[d5:d6]
If CheckBox9.Value = True Then
Worksheets("Sheet2").Range("A5").Value = "Air Emissions"
Worksheets("Sheet2").Range("B5").Value = "Point Source Air Emission"
Worksheets("Sheet2").Range("C5").Value = "CO2"
Else
Worksheets("Sheet2").Range("B5").ClearContents
End If
If Worksheets("Sheet2").Range("A5").Value = "Air Emissions" Then
With n.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=AirEmissionsI"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End
End If
End Sub


_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-20 15:43 ]
NateO is offline   Reply With Quote
Old May 20th, 2002, 07:02 PM   #3
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Quote:
The Code bombs at [Worksheets("Sheet2").Range("D5:D6").Select]. How do I state that I want to Select Sheet2, Range D5 without activating the sheet?
Just a little addendum to Nate's sage advice.

You can't select a cell if the sheet is nnot activated. It's against the rules.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old May 20th, 2002, 07:37 PM   #4
kls
Board Regular
 
Join Date: May 2002
Posts: 69
Default

Thank you for your reply...only now I'm getting an error: Application-defined or object-defined error at [.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=AirEmissionsI"].

I did not want to "activate" Sheet2 because I want to remain on Sheet1; not flip back & forth.
kls is offline   Reply With Quote
Old May 20th, 2002, 07:54 PM   #5
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

The way I wrote the code above (in part 2), you won't be selecting any cells. The data validation insert above works well for me except in the case where I don't have a range named AirEmissionsI. Better safe than sorry as well and capitalize it the same in both the range naming and vba procedure.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-20 20:09 ]
NateO is offline   Reply With Quote
Old May 21st, 2002, 01:37 PM   #6
kls
Board Regular
 
Join Date: May 2002
Posts: 69
Default

I've checked everything and am still getting an error at the .Add Type:=xlValidateList...

If I use Application.Goto Sheets("sheet2").[d5:d6] as you suggested previously; that works; only it it changes my screen to sheet2. There are several checkboxes and I would like to stay on Sheet1 instead of flipping back & forth between the two sheets.

Any other suggestions??
kls is offline   Reply With Quote
Old May 21st, 2002, 01:55 PM   #7
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

No need to to select the sheet. Allow me to ask what:

"=AirEmissionsI"

represents? Should be a named range, if you hit f5 can you goto this range? If I set a cell with this as a named range, I can run the code above in xl2000.

__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old May 21st, 2002, 02:03 PM   #8
kls
Board Regular
 
Join Date: May 2002
Posts: 69
Default

Yes, "=AirEmissionsI" is a named range and I can go to this range by hitting f5.

The range is on a different / separate sheet but I wouldn't think that matters.

I'm using XL2002
kls is offline   Reply With Quote
Old May 21st, 2002, 02:36 PM   #9
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Because it's a named range, it doesn't matter. I rewrote the if to combine the first if with the 2nd. I have checkbox9 on the first sheet and "AirEmissionsI" on sheet3. The following works in Excel 2000 with no selecting (& fairly quickly):


Sub redo2()
Dim n As Range
Set n = Sheets("sheet2").Range("d5:d6")
If Sheets(1).CheckBox9.Value = True Then
Worksheets("Sheet2").Range("A5").Value = "Air Emissions"
Worksheets("Sheet2").Range("B5").Value = "Point Source Air Emission"
Worksheets("Sheet2").Range("C5").Value = "CO2"

With n.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=AirEmissionsI"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With

Else:
Worksheets("Sheet2").Range("B5").ClearContents
End If

End Sub


I suppose it's possible that xl2002 won't use this methodology but it seems that XL has gotten more flexible with code over time. Wish I had xl2002 to test it with.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-21 13:47 ]
NateO is offline   Reply With Quote
Old May 21st, 2002, 03:17 PM   #10
kls
Board Regular
 
Join Date: May 2002
Posts: 69
Default

I wish you had XL2002 also!!!

Thanks for your interest. Right now it's looks like my only alternative is to add a command button to add the listbox...
kls 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 04:43 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