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 Mar 10th, 2002, 05:30 AM   #1
tanayhan
New Member
 
Join Date: Feb 2002
Location: Turkey
Posts: 36
Default

I am assigning some cell values to some variables in a macro to use later as default values. My problem is how can I get the values assigned to variables to assign them as default values in the cells? I must do this in another macro.

Thanks,
Ayhan
tanayhan is offline   Reply With Quote
Old Mar 10th, 2002, 02:49 PM   #2
Dan Aragon
MrExcel MVP
 
Join Date: Feb 2002
Location: Minnesota
Posts: 92
Default

Your question is a little vague. Can you provide an example of what you are trying to do? I'm assuming that you know how to assign a value to a cell and that isn't the issue.
__________________
HTH,

Dan
darag2358@yahoo.com
Dan Aragon is offline   Reply With Quote
Old Mar 11th, 2002, 04:40 AM   #3
tanayhan
New Member
 
Join Date: Feb 2002
Location: Turkey
Posts: 36
Default

Quote:
On 2002-03-10 13:49, Dan Aragon wrote:
Your question is a little vague. Can you provide an example of what you are trying to do? I'm assuming that you know how to assign a value to a cell and that isn't the issue.
In a worksheet, in the beginning I calculate a value for Cell B1. And in a macro called GetX() I assign the calculated value of B1 to variable X to use it later, as following.

Sub GetX()
Dim X
X = Range("B1").Value
End Sub

Then if I don't like the value I calculated in B1, I change the value in B1 manually. The value in the variable in X stays as original value to get later if I need it.

My problem is how to get the X value again if I need it from another macro, and assign it to cel B1.

I hope you understand what I mean.

Thanks,

Ayhan
tanayhan is offline   Reply With Quote
Old Mar 11th, 2002, 04:54 AM   #4
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi

In the sheet that house the value of B1 put this in the Private module of the Worksheet Object(right click on name tab and selec "View Code")

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then iVal = Target
End Sub

Then at the top a standard module put:

Public iVal as Integer


Dave Hawley is offline   Reply With Quote
Old Mar 11th, 2002, 09:37 AM   #5
tanayhan
New Member
 
Join Date: Feb 2002
Location: Turkey
Posts: 36
Default

Quote:
On 2002-03-11 03:54, Dave Hawley wrote:
Hi

In the sheet that house the value of B1 put this in the Private module of the Worksheet Object(right click on name tab and selec "View Code")

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then iVal = Target
End Sub

Then at the top a standard module put:

Public iVal as Integer


Thanks Dave,

It worked, but there is something wrong. Everytime I enter a new value to B1, iVal takes the new value. I want it to take the value at the beginning. For example, in the beginnig I entered 10 for B1. It wil be stored as 10. After that, I can enter several different values for B1. When I want to retreive the first value (that was 10) for B1 the macro should retreive the first value (10). I hope I could explain it.

Thanks,
Ayhan
tanayhan is offline   Reply With Quote
Old Mar 11th, 2002, 09:44 AM   #6
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi

Depends what you mean by "the beggining"? But try this

Private Sub Worksheet_Change(ByVal Target As Range)
iFirstTime = 1 + iFirstTime
If iFirstTime <> 1 Then exit sub
If Target.Address = "$B$1" Then iVal = Target

End Sub

Then at the top a standard module put:

Public iVal as Integer
Public iFirstTime As Long

Dave Hawley is offline   Reply With Quote
Old Mar 13th, 2002, 03:57 AM   #7
tanayhan
New Member
 
Join Date: Feb 2002
Location: Turkey
Posts: 36
Default

Quote:
On 2002-03-11 08:44, Dave Hawley wrote:
Hi

Depends what you mean by "the beggining"? But try this

Private Sub Worksheet_Change(ByVal Target As Range)
iFirstTime = 1 + iFirstTime
If iFirstTime <> 1 Then exit sub
If Target.Address = "$B$1" Then iVal = Target

End Sub

Then at the top a standard module put:

Public iVal as Integer
Public iFirstTime As Long

Thanks Dave,

It worked. You asked me what I mean by "the beginning". I mean the first value I entered.
Now I have a new problem with this macro. How can I do this for more than one variables. Say for three variables.

Kind regards,
Ayhan
tanayhan is offline   Reply With Quote
Old Mar 13th, 2002, 04:32 AM   #8
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Tr this, just alter the cell addresses to suit.

At the top of a standard module put

Public iVal1 As Integer
Public iVal2 As Integer
Public Ival3 As Integer
Public iFirstTime1 As Long
Public iFirstTime2 As Long
Public iFirstTime3 As Long




The in the Worksheet module put

Private Sub Worksheet_Change(ByVal Target As Range)
If Not IsNumeric(Target) Then Exit Sub

Select Case Target.Address
Case "$B$1"
iFirstTime1 = 1 + iFirstTime1
If iFirstTime1 <> 1 Then Exit Sub
iVal1 = Target

Case "$B$5"
iFirstTime2 = 1 + iFirstTime2
If iFirstTime2 <> 1 Then Exit Sub
iVal2 = Target

Case "$B$5"
iFirstTime3 = 1 + iFirstTime3
If iFirstTime3 <> 1 Then Exit Sub
Ival3 = Target
End Select

End Sub
Dave Hawley is offline   Reply With Quote
Old Mar 17th, 2002, 07:42 AM   #9
tanayhan
New Member
 
Join Date: Feb 2002
Location: Turkey
Posts: 36
Default

Quote:
On 2002-03-13 03:32, Dave Hawley wrote:
Tr this, just alter the cell addresses to suit.

At the top of a standard module put

Public iVal1 As Integer
Public iVal2 As Integer
Public Ival3 As Integer
Public iFirstTime1 As Long
Public iFirstTime2 As Long
Public iFirstTime3 As Long




The in the Worksheet module put

Private Sub Worksheet_Change(ByVal Target As Range)
If Not IsNumeric(Target) Then Exit Sub

Select Case Target.Address
Case "$B$1"
iFirstTime1 = 1 + iFirstTime1
If iFirstTime1 <> 1 Then Exit Sub
iVal1 = Target

Case "$B$5"
iFirstTime2 = 1 + iFirstTime2
If iFirstTime2 <> 1 Then Exit Sub
iVal2 = Target

Case "$B$5"
iFirstTime3 = 1 + iFirstTime3
If iFirstTime3 <> 1 Then Exit Sub
Ival3 = Target
End Select

End Sub
Thanks Dave,

It worked as the way I want. Sorry for being too late to confirm.

Kind regards,

Ayhan
tanayhan 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 07:25 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