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 21st, 2002, 12:54 PM   #1
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I am trying to add an Array Formula in my macro but it isn’t working. Here's the formula:

{=MAX(IF(G2:G207="Y",I2:I207))}

I need the ranges for the G and I Column to be done with using the length of Column I minus the Heading so it Column I has 35 values, I need the ranges to be G2:G36 and I2:I36.

Range("I2").Select
Range(Selection, Range("I65536").End(xlUp)).Select
RowCounter = Selection.Count
Range("L7").Select
Selection.FormulaArray = "=MAX(IF(G2:" & Range("G" & RowCounter + 1).Address & "=Y,(I2:" & Range("I65536").End(xlUp).Address & "))"

Can anybody help?
Cosmos75 is offline   Reply With Quote
Old Mar 21st, 2002, 01:27 PM   #2
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Hi,

The formula you are trying to use doesn't work in Excel. {=MAX(IF(G2:G207="Y",I2:I207))}

Just wondering what are you trying to achieve?

BabyTiger is offline   Reply With Quote
Old Mar 21st, 2002, 01:45 PM   #3
Dave Patton
Board Regular
 
Join Date: Feb 2002
Location: Calgary, Alberta Canada
Posts: 2,065
Default


You could consider Dynamic Ranges
-rG
-rI

Then array enter the formula

=MAX(IF(rG="Y",rI))
Dave Patton is offline   Reply With Quote
Old Mar 21st, 2002, 01:56 PM   #4
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

BabyTiger,

{=MAX(IF(G2:G207="Y",I2:I207))}

The fomula does work, (I know I use it)but you have to type

=MAX(IF(G2:G207="Y",I2:I207)) and then enter it by using Crtl-Shift-Enter and not Enter by itself.

Dave Patton,

Do Dynamic Ranges work in a Macro?


Beside shouldn't the using Range("I2",Range("I365536").End(xlUp).Address).Select accomplish the same thing in a macro?

What I am trying to do is to get excel enter the formula and the copy it to a range that is based on the length of the list it refers to. I can get the ranges to work but am not quite sure why the array formula entered in the macro doesn't work.

[ This Message was edited by: Cosmos75 on 2002-03-21 12:58 ]
Cosmos75 is offline   Reply With Quote
Old Mar 21st, 2002, 02:07 PM   #5
Dave Patton
Board Regular
 
Join Date: Feb 2002
Location: Calgary, Alberta Canada
Posts: 2,065
Default


You may want to research redimensioning the
array after it is defined.

Could you define the range and then put it
into the array.
Dave Patton is offline   Reply With Quote
Old Mar 21st, 2002, 02:59 PM   #6
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Sorry, wasn't thinking.

You might want to try the following:

Range("I2").Select
rowcounter = Selection.Cells(xlLast).Row
Range("L7").Select
Selection.FormulaArray = "=MAX(IF(G2:G" & rowcounter & "=" & """" & "Y" & """" & ",I2:I" & rowcounter & "))"

BabyTiger is offline   Reply With Quote
Old Mar 21st, 2002, 03:02 PM   #7
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

My apologies, the second line should be:


rowcounter = Selection.SpecialCells(xlLastCell).Row

BabyTiger is offline   Reply With Quote
Old Mar 21st, 2002, 03:17 PM   #8
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

BabyTiger,
THANKS! It works great! Guess I didn't have enough "s, actually not sure when and where to put them

Range("I2").Select
rowcounter = Selection.Cells(xlLast).Row
Range("L7").Select
Selection.FormulaArray = "=MAX(IF(G2:G" & rowcounter & "=" & """" & "Y" & """" & ",I2:I" & rowcounter & "))"

What's the difference between
rowcounter = Selection.SpecialCells(xlLastCell).Row and
rowcounter = Selection.Cells(xlLast).Row ?

I used the first one and it worked? Haven't tried the second one yet.

THANKS A BUNCH!!

Edit: I just noticed that the first time it only choose I2:I2 and the second one corrected it.

It does hoever choose I2:I1003, and there's nothing below I71??

Also when I do an Range("D65336").End(xlup).Select, it chooses D501 and there's nothing there as well. D2:D63 has a list of A,B,Cs with some empty cells. From D501 if I do an End(xlUp) it goes straight to D1? Any ideas why?

[ This Message was edited by: Cosmos75 on 2002-03-21 14:23 ]
Cosmos75 is offline   Reply With Quote
Old Mar 21st, 2002, 03:44 PM   #9
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Hi,

The first line of code:
selection.cells(xllast).row is incorrect, basically, it didn't go anywhere.

The second line I have suggested, is selecting the row number of the last cell of the active sheet. Same thing as when you press "ctrl" + "end".

So that will cover all the activecells you have got on the page.

Sorry for the lack of explanation.
BabyTiger is offline   Reply With Quote
Old Mar 21st, 2002, 03:56 PM   #10
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

BabyTiger,

Thanks for the explanation! I've been tring to pick up some VBA Language by messing around with macros provided by people with you, usually without an explanation so the fact that you were willing to explain that to me is of great help!

THANKS

When I do Ctrl-End it brings me to Q1003, I have no data below row 71 and beyond Column Q. Have no idea what is going on?!
Cosmos75 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:58 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