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 Jan 3rd, 2004, 06:46 PM   #1
DaddyWeg
 
Join Date: Dec 2003
Location: St. Clair Shores, MI
Posts: 18
Default Cell linked to spinbutton resetting!

Probably an easy one for you pros, but it's got me confused!

I have a spinbutton (1) linked to cell "g16" which has an initial value of 60 and is set to scroll up to 92. I have another spinbutton (2) linked to cell "g25" which simply scrolls between 0 and 8.5. If I use spinbutton1 to change "g16" to 70 (or any value), as soon as I use spinbutton2 "g16" changes back to the initial value of 60. How can I prevent this from happening? (Both spinbuttons have code written to control their ranges and values)

__________________
Thanks for the HELP!

DaddyWeg
DaddyWeg is offline   Reply With Quote
Old Jan 3rd, 2004, 07:15 PM   #2
bydesign
 
bydesign's Avatar
 
Join Date: Nov 2003
Location: Racine, WI USA
Posts: 184
Default Re: Cell linked to spinbutton resetting!

YO DaddyWeg

Sounds like some code is crossed somewhere... How about you post the code for those spinbutton procedures...
__________________
Thanks for the help,
Have a great day!

Scott
bydesign is offline   Reply With Quote
Old Jan 3rd, 2004, 07:21 PM   #3
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,449
Default Re: Cell linked to spinbutton resetting!

Hi DaddyWeg:

I installed the two SpinButton controls in a woksheet, assigned them the values as you posted, linked those to cells G16 and G25 -- and I could not reproduce the error you are experiencing.

How about if you post the code you are using and describe where the controls have been installed -- so the viewers can see what you are working with, and where the problem might lie.
__________________
Regards!

Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
www.energyefficientbuild.com
Yogi Anand is offline   Reply With Quote
Old Jan 3rd, 2004, 09:26 PM   #4
DaddyWeg
 
Join Date: Dec 2003
Location: St. Clair Shores, MI
Posts: 18
Default Re: Cell linked to spinbutton resetting!

Spinbutton3 is linked to "g16"
Spinbutton5 is linked to "g27"
Both reset to the "value " assigned in the code whenever spinbutton4 or 6 are used.

Here is everything I have going on in this worksheet!




Private Sub ComboBox2_Change()

Range("G14") = Val(ComboBox2.Value)

End Sub

Private Sub ComboBox3_Change()

Range("G25") = Val(ComboBox3.Value)

End Sub

Private Sub CommandButton1_Click()
clearform
End Sub

Private Sub SpinButton4_SpinDown()

If Range("G19").Value = 0 Then Exit Sub
Range("G19").Value = Range("G19").Value - 0.1



End Sub



Private Sub SpinButton4_SpinUp()

If Range("G19").Value = 8.5 Then Exit Sub
Range("G19").Value = Range("G19").Value + 0.1



End Sub



Private Sub SpinButton6_SpinDown()

If Range("G30").Value = 0 Then Exit Sub
Range("G30").Value = Range("G30").Value - 0.1


End Sub



Private Sub SpinButton6_SpinUp()

If Range("G30").Value = 8.5 Then Exit Sub
Range("G30").Value = Range("G30").Value + 0.1

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("G14").Value = 75 Then
SpinButton3.Min = 25
SpinButton3.Max = 57
SpinButton3.Value = 25
ElseIf Range("G14").Value = 125 Then
SpinButton3.Min = 60
SpinButton3.Max = 92
SpinButton3.Value = 60
ElseIf Range("G14").Value = 0 Then
SpinButton3.Min = 0
SpinButton3.Max = 0
SpinButton3.Value = 0
End If

If Range("G25").Value = 60 Then
SpinButton5.Min = 0
SpinButton5.Max = 32
SpinButton5.Value = 0
ElseIf Range("G25").Value = 0 Then
SpinButton5.Min = 0
SpinButton5.Max = 100
SpinButton5.Value = 0
End If

End Sub





Thanks for the help guys!
__________________
Thanks for the HELP!

DaddyWeg
DaddyWeg is offline   Reply With Quote
Old Jan 4th, 2004, 06:58 PM   #5
DaddyWeg
 
Join Date: Dec 2003
Location: St. Clair Shores, MI
Posts: 18
Default Re: Cell linked to spinbutton resetting!

bump
__________________
Thanks for the HELP!

DaddyWeg
DaddyWeg is offline   Reply With Quote
Old Jan 4th, 2004, 08:02 PM   #6
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,449
Default Re: Cell linked to spinbutton resetting!

Hi DaddyWeg:

I am sorry, I can not get a clear picture of what you are trying to do. Where are the SpinButton Controls? If they are on UserForm1, in the code for the Worksheet_Change event, in working with SpinButton Controls, I had to use the associated UserForm, such as ...
Code:
With UserForm1
     .SpinButton3 .....
     .SpinButton3 .....
End With
I also did not follow what you are trying to do with the CommandButton1 code ...
ClearForm

I am sorry, I could not be of more help.
__________________
Regards!

Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
www.energyefficientbuild.com
Yogi Anand is offline   Reply With Quote
Old Jan 4th, 2004, 08:30 PM   #7
DaddyWeg
 
Join Date: Dec 2003
Location: St. Clair Shores, MI
Posts: 18
Default Re: Cell linked to spinbutton resetting!

Hey Yogi!

Thanks for the response! Sorry I'm not being clear enough. Maybe this will help. I started a new worksheet. Created a spinbutton and linked it to a cell. I pasted the following as my code for sheet 1. The spinbutton works the way the code says by setting the value correctly and limiting it's upper and lower values. When I select any other cell, enter a number and hit enter, the cell linked to my spinbutton changes back to SpinButton1.Value. How do I get it to stay at whatever I spun it up or down to.



Code:
Private Sub Worksheet_Change(ByVal Target As Range) 

If Range("G14").Value = 75 Then 
SpinButton1.Min = 25 
SpinButton1.Max = 57 
SpinButton1.Value = 25 
ElseIf Range("G14").Value = 125 Then 
SpinButton1.Min = 60 
SpinButton1.Max = 92 
SpinButton1.Value = 60 
ElseIf Range("G14").Value = 0 Then 
SpinButton1.Min = 0 
SpinButton1.Max = 0 
SpinButton1.Value = 0 
End If
__________________
Thanks for the HELP!

DaddyWeg
DaddyWeg is offline   Reply With Quote
Old Jan 4th, 2004, 09:03 PM   #8
parry
MrExcel MVP
 
parry's Avatar
 
Join Date: Aug 2002
Location: Wellington, New Zealand
Posts: 3,355
Default Re: Cell linked to spinbutton resetting!

Hi DW, Im coming into this thread a bit late but what control did you use when you placed it on the sheet. A control from the Forms toolbar works differently from a control from the Visual Basic toolbar.
parry is offline   Reply With Quote
Old Jan 4th, 2004, 10:44 PM   #9
DaddyWeg
 
Join Date: Dec 2003
Location: St. Clair Shores, MI
Posts: 18
Default Re: Cell linked to spinbutton resetting!

Parry,

The spinbutton is from the visual basic toolbar.

__________________
Thanks for the HELP!

DaddyWeg
DaddyWeg is offline   Reply With Quote
Old Jan 4th, 2004, 11:45 PM   #10
parry
MrExcel MVP
 
parry's Avatar
 
Join Date: Aug 2002
Location: Wellington, New Zealand
Posts: 3,355
Default Re: Cell linked to spinbutton resetting!

Hi, theres a bit going on here and would take some time for me to recreate it. Its a pity you cant upload files on MrExcel as it would be much easier to understand in seeing the actual sheet.

If the problem is only occuring when you change a cell then it must be your Worksheet_Change event thats causing it.

There are 3 conditions where G14 is either 75,125 or 0. What happens if G14 is neither of these values?

The Worksheet_Change event runs whenever there is a change to any cell in the sheet, so maybe you want to amend this with an additional condition test so it only changes the spin min/max if there is a change to cell G14? The following amendment should fix that...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Set Rng = Application.Intersect(Range(Target.Address), Range("G14"))

If Not Rng Is Nothing Then 'do this only if cell changed was in G14
    If Range("G14").Value = 75 Then
        SpinButton1.Min = 25
        SpinButton1.Max = 57
        SpinButton1.Value = 25
    ElseIf Range("G14").Value = 125 Then
        SpinButton1.Min = 60
        SpinButton1.Max = 92
        SpinButton1.Value = 60
    ElseIf Range("G14").Value = 0 Then
        SpinButton1.Min = 0
        SpinButton1.Max = 0
        SpinButton1.Value = 0
    End If
End If
End If

End Sub
Has this helped or you still have a problem?
parry 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 +1. The time now is 05:05 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2010 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