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 22nd, 2002, 08:21 PM   #1
ChrisY
New Member
 
Join Date: Feb 2002
Location: California
Posts: 7
Default

Let me start with a fact. I know just enough about VBA to make myself very dangerous. Having said that, I have been playing with a formula that uses Offset. What I am trying to do is get VBA to read a variable value (CellOffset) from a cell on another worksheet, and have the offset value in the foumula changed to the value of CellOffset and then written into a cell on the active worksheet. I can see that the CellOffset is taking the right value - still can't get it into the formula below.

=IF(ISNUMBER($D2),OFFSET(('DN01'!$A$1),(MATCH(($D2),'DN01'!$D:$D,0)-1),CellOffset),"")

I have been able to get the formula into the target cell; however, the offset value is entered as "CellOffset", not the variable value.

Is this possible or am I just being dumb?

Any suggestions would be greatly appreciated.

Thanks

ChrisY
ChrisY is offline   Reply With Quote
Old Mar 22nd, 2002, 08:30 PM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

I do not know how to put a formula into a cell via code, but I am guessing that it would be treated by VB as a string. It is passing a string in your case "CellOffset"

To include a Variable in a string, the typical sytax is thus:


IntegerVariable = 31

StringPlusVar = "I am" & IntegerVariable & " years old."

Yields

I am 31 years old

In other words, include use " & before the variable you are passing and & " after the variable.

Have Fun!


[ This Message was edited by: TsTom on 2002-03-22 19:31 ]
Tom Schreiner is offline   Reply With Quote
Old Mar 22nd, 2002, 09:11 PM   #3
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi Chris,

=IF(ISNUMBER($D2),OFFSET(('DN01'!$A$1),(MATCH(($D2),'DN01'!$D:$D,0)-1),CellOffset),"")

In VBA would be inserted as

=IF(ISNUMBER(R2C4),OFFSET(('DN01'!R1C1),(MATCH((R2C4),'DN01'!C4,0)-1)," & CellOffset.value & "),"""")"

Note the double, double-quotes to give the blank.

Warning, your reference to $D2 is a relative row reference. The VBA line I gave you makes it fully absolute. If you need relative row, you will change it to R[?]C4.

HTH,
Jay
Jay Petrulis is offline   Reply With Quote
Old Mar 22nd, 2002, 09:43 PM   #4
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

First off, I think your formula is wrong, try the following:

=IF(ISNUMBER($D2)=TRUE,OFFSET('DN01'!$A$1,MATCH($D2,'DN01'!$D:$D,0)-1,CellOffset),"is not a number")

Secondly you cannot use variable names in the formula for a cell. You can do all the calculations in VBA and then have the result put into a cell. Try the following VB code:

Dim ColumnOffset, RowOffset, FirstRow, LastRow As Integer
LastRow= 2
LastRow= 3
ColumnOffset = 9
For i = FirstRow To LastRow
RowOffset = Application.WorksheetFunction.Match(Worksheets("Sheet1").Range("d" & i), Worksheets("DN01").Columns(4), 0)
If Application.WorksheetFunction.IsNumber(Worksheets("Sheet1").Range("d" & i).Value) = True Then
ActiveCell.Offset(i - 2, 0).Value = Worksheets("DN01").Range("a1").Offset(RowOffset, ColumnOffset)
Else: ActiveCell.Offset(i - 2, 0).Value = "D2 is not a number"
End If
Next i

Substitute the 9 in ColumnOffset with the value or range of your choice, substitute 2 in FirstRow for the row you want to start on in column D, and substitute 3 in LastRow for the row you want to finish on in column D.

_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-03-22 20:44 ]
Al Chara is offline   Reply With Quote
Old Mar 26th, 2002, 11:19 AM   #5
ChrisY
New Member
 
Join Date: Feb 2002
Location: California
Posts: 7
Default

Sorry for not getting back to you and thanks for all the input. I was out of town for a few days * not * thinking. However, this is still bothering me. I have tried several of the solutions offered but still can't get it to work when the "=" is included in the formula.

What I'm trying to do is limit the size of the appllication and reduce the amount of traffic over the network by just passing the offset required in each formula, as the formula is basically the same thoughout the worksheet. As it is now, each time the user calculates a report, a 10 column X 75 row area of one of eight different worksheets gets copied from a server to the local machine. These worksheets presently include both the titles of the various sections and the formulas that pull the data. As the server-based reports may change, I was trying to keep them in a central area so I didn't have to update 300 copies of the application after it is distributed.

Any thoughts?

Thanks again for all the help.

ChrisY
ChrisY 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 03:32 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