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 22nd, 2002, 01:17 PM   #1
mootz
New Member
 
Join Date: May 2002
Posts: 7
Default

I cannot set the value of a cell in the same book but different sheet. I'm new to Excel/VBA but alot of typing with Visual Foxpro (and others). I have tried every possible combo and every read Kofler's book on Excel VBA. Here is my code:

Worksheets("Stat Sheet").Range("B9").Value = 12

I can run it in the immediate window but get a "VALUE#" error when I run it a single line VBA function. Same problem in Excel 97 and 2000.

TIA, John (P.S. I tried to search here but keep getting error with the SQL string).
mootz is offline   Reply With Quote
Old May 22nd, 2002, 01:23 PM   #2
cornbread
Board Regular
 
Join Date: Apr 2002
Location: Oregon
Posts: 77
Default

you need to say
ActiveWorkbook.Sheets(2).Range("b9") = 12


[ This Message was edited by: cornbread on 2002-05-22 12:24 ]
cornbread is offline   Reply With Quote
Old May 22nd, 2002, 01:47 PM   #3
mootz
New Member
 
Join Date: May 2002
Posts: 7
Default

Thanks, I tried your code but still get the same error.

Any other ideas?
John
mootz is offline   Reply With Quote
Old May 22nd, 2002, 02:05 PM   #4
DZarlengo
Board Regular
 
Join Date: May 2002
Posts: 63
Default

Did you try:

ActiveWorkBook.WorkSheets("Stat Sheet").Range("B9").Value = 12
DZarlengo is offline   Reply With Quote
Old May 22nd, 2002, 02:07 PM   #5
cornbread
Board Regular
 
Join Date: Apr 2002
Location: Oregon
Posts: 77
Default

you need to say
sub put1()
ActiveWorkBook.Sheets(2).Range("b2") = 12
end sub

or

Sub put2()
Sheet2.Range("b2") = 12
End Sub

whatever the name of the sheet within vba is is what you need to use not the name on the sheet tab.


[ This Message was edited by: cornbread on 2002-05-22 13:07 ]
cornbread is offline   Reply With Quote
Old May 22nd, 2002, 03:18 PM   #6
mootz
New Member
 
Join Date: May 2002
Posts: 7
Default

Ok, does anybody have a hammer. I need to hit my head.

I can get the Sub to run via the Immediate window but not directly from Excel via a Function statement. The function only calls the Sub. If a comment out the Sub call the function works, otherwise I get the same "#VALUE" error. BTW, I ca also succesfully can the function from the immediate window. Any blows form the hammer for me??

John
mootz is offline   Reply With Quote
Old May 22nd, 2002, 03:22 PM   #7
James
Board Regular
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Hi mootz,

Before you use a hammer on yourself, can yo post your code?

Regards,
James
James is offline   Reply With Quote
Old May 22nd, 2002, 03:36 PM   #8
mootz
New Member
 
Join Date: May 2002
Posts: 7
Default

Here is the basic code (2-300 lines in rest):

Public Function Temp() As Integer
Put1
Temp = 1
End Function


Sub Put1()
ActiveWorkbook.Sheets("Day 1").Range("c9") = 545
End Sub

The function calls the Sub because I don't know how to call a Sub directly from Excel (or how to spell the topic).

John
mootz is offline   Reply With Quote
Old May 22nd, 2002, 03:43 PM   #9
James
Board Regular
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

What about:

Range("C9").Value = 545

Regards,
James
James is offline   Reply With Quote
Old May 22nd, 2002, 03:50 PM   #10
mootz
New Member
 
Join Date: May 2002
Posts: 7
Default

I need to change the cell in a different worksheet, so I need the Worksheet(x) object.

I did try it (and everything else a week ago) but still same error if called from Excel (vs immediate window).

john
mootz 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 01:19 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