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 27th, 2002, 04:34 AM   #1
chaju
Board Regular
 
Join Date: Mar 2002
Posts: 82
Default

Thanks to those who take a look at this and help!

Suppose the file consists of 2 worksheets

For the both sheets:
Cell A1 have date: 25-Mar-02

Can I have a Macro button so that it inputs (when pressed) this formula into Cell C1 (BOTH Sheets): =C:\test\[Valuation 25-Mar-02.xls]Ingenium'!$E$11

Note: the date within the file name corresponds to the date in Cell A1 for both sheet.

Suppose both sheet's Column A has already been filled with date. The next step I wish the macro to do is whenever I press the button it will fill the formula mention above into C2 (for both sheets). I must ensure Cell C2 formula (in both sheets)have the file name with the date correspond to their sheet's Cell A2's date.

when I press the button it will do the same to cell C3 with both formula reading the dates in cell A3 (for both sheets)

As I am very new to macro Please asist step by step of how to create a macro button and where to put the VB code...

Many Many Many thanks to the helper,,,
Deeply appreciated



chaju is offline   Reply With Quote
Old Mar 27th, 2002, 05:38 PM   #2
chaju
Board Regular
 
Join Date: Mar 2002
Posts: 82
Default

help!!
chaju is offline   Reply With Quote
Old Mar 27th, 2002, 06:57 PM   #3
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi chaju!

'Please copy both of codes into a standard module.

Sub InputsFormula()
Dim sh(0 To 1) As Worksheet, cnt As Integer, lngRow As Long

Set sh(0) = Sheets("Sheet1") 'change to a sheet name to input Formula
Set sh(1) = Sheets("Sheet2") 'same as above

lngRow = Selection.Row

For cnt = 0 To 1
With sh(cnt)
.Cells(lngRow, 3).Formula = _
"'=C:\\test\\[Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$11"
End With
Next
End Sub

'Please active the sheet with which you want to make a button,
'and execute "Sub MakeBottonOnActiveSheet".

Sub MakeBottonOnActiveSheet()
Dim rngBt As Range, objBt As Button
Set rngBt = Application.InputBox _
("Select range where you want to make Button", Type:=8)
With rngBt
Set objBt = ActiveSheet.Buttons.Add(.Left, .Top, .Width, .Height)
End With
With objBt
.OnAction = "InputsFormula"
.Text = "Click"
End With
End Sub
Colo is offline   Reply With Quote
Old Mar 27th, 2002, 07:02 PM   #4
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Please reduce the number of "/" in the formula.
It seems that the character became strange Because, my Excel is a Japanese version.
Regards,
Colo is offline   Reply With Quote
Old Mar 27th, 2002, 08:57 PM   #5
chaju
Board Regular
 
Join Date: Mar 2002
Posts: 82
Default

Thanks very much! but I find a mistake in my content..

In the 4th paragraph I have:
"Can I have a Macro button so that it inputs (when pressed) this formula into Cell C1 (BOTH Sheets): =C:\\test\\[Valuation 25-Mar-02.xls]Ingenium'!$E$11 "

it should be:
"Can I have a Macro button so that it inputs (when pressed) this formula into Cell C1 (1st Sheet): =C:test[Valuation 25-Mar-02.xls]Ingenium'!$E$11, and input this formula into Cell C1 (2nd Sheet): =C:test[Valuation 25-Mar-02.xls]Ingenium'!$E$4"

Sorry about that,, But I guess I should can the code much..

So, I look forward to see the amended code..

Many thanks
chaju is offline   Reply With Quote
Old Mar 27th, 2002, 09:12 PM   #6
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hello again, the amended code is following...


Sub InputsFormula()
Dim lngRow As Long
lngRow = Selection.Row
With Sheets("Sheet1")
.Cells(lngRow, 3).Formula = _
"=C://test//[Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$11"
End With
With Sheets("Sheet2")
.Cells(lngRow, 3).Formula = _
"=C://test//[Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$4"
End With
End Sub
Colo is offline   Reply With Quote
Old Mar 27th, 2002, 09:15 PM   #7
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

The characters "//" in above code mean "".
Thanks,
Colo is offline   Reply With Quote
Old Mar 27th, 2002, 09:40 PM   #8
chaju
Board Regular
 
Join Date: Mar 2002
Posts: 82
Default

Thanks I have the code now.. But it doesn't work ... I think is the sheet name problem.

Suppose My 1st Sheet have name MonMkt
Is it right that the code should have:

With Sheets("MonMkt") instead of the suggested:
With Sheets("Sheet1")
That's what I have,, but not working.. pls advise.. sorry to bother again.
chaju is offline   Reply With Quote
Old Mar 27th, 2002, 09:49 PM   #9
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi.
Does any error message come out?
I think, how to write sheet name is no problem as you wrote.
You should select "Row" before click button.
If you want to formula into Cell C1 then please select any cells in row1.
Do I make myself clear? Sorry, I am not an English native.
Regards,
Colo is offline   Reply With Quote
Old Mar 27th, 2002, 09:56 PM   #10
chaju
Board Regular
 
Join Date: Mar 2002
Posts: 82
Default

Thanks Colo,, I have modified the code you gave me, now my sheets have 10sheets, only 8 sheets are needed to perform action with that button. You can see the 8 sheets name below. After editing the code, I press F5 (in VB) (F5 means Run Sub/UserForm) and error message pop up say: "RUN time error '9': Subscript out of range"

Can you pls check my modified code and help me please........ please, we are nearly there!! Code as follow:

Sub InputsFormula()
Dim lngRow As Long
lngRow = Selection.Row
With Sheets("MonMkt")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$4"
End With
With Sheets("GEqty")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$11"
End With
With Sheets("GBond")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$6"
End With
With Sheets("USEqty")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$9"
End With
With Sheets("USBond")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$5"
End With
With Sheets("EuEqty")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$10"
End With
With Sheets("AsianEqty")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$8"
End With
With Sheets("HKEqty")
.Cells(lngRow, 5).Formula = _
"='I:VULYEAR 20022nd QtrValuation[Fortune Valuation " & .Cells(lngRow, 1).Text & ".xls]Ingenium'!$E$7"
End With
End Sub



Sub MakeBottonOnActiveSheet()
Dim rngBt As Range, objBt As Button
Set rngBt = Application.InputBox _
("Select range where you want to make Button", Type:=8)
With rngBt
Set objBt = ActiveSheet.Buttons.Add(.Left, .Top, .Width, .Height)
End With
With objBt
.OnAction = "InputsFormula"
.Text = "Click"
End With
End Sub
chaju 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 11:42 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