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, 07:58 AM   #1
Guest
 
Posts: n/a
Default

I have a row of columns numbered 1-10 (Say A1-A10) and the cells below may have information in depending on the result of another formula. How can I get Excel to look at the information in row B, starting with column A10? If there is no entry in B10 I need it to look at B9, and so on until it finds a cell with some information in.

Hope this makes sense to someone! Please help!

Thanks.
  Reply With Quote
Old Mar 10th, 2002, 08:04 AM   #2
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi

I don't think a Loop would be best, try the Find method. This can easily be restricted to a certain range and also include/exclude others. I am not very clear on the specific ranges you want but the code below will only look in Range("A11:B20")

Range("A11:B20").Find(What:="7", After:=Range("A11"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Activate
Dave Hawley is offline   Reply With Quote
Old Mar 10th, 2002, 02:48 PM   #3
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-10 07:04, Dave Hawley wrote:
Hi

I don't think a Loop would be best, try the Find method. This can easily be restricted to a certain range and also include/exclude others. I am not very clear on the specific ranges you want but the code below will only look in Range("A11:B20")

Range("A11:B20").Find(What:="7", After:=Range("A11"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Activate

One small point.
If the first cell containing "7" needs to be located, would suggest using After:-Range("B20") instead of After:-Range("A11").
If "7" is in cell A11 and also in B2(say), B2 will be "found" if After:-Range("A11") is used.

  Reply With Quote
Old Mar 10th, 2002, 07:26 PM   #4
SamS
Board Regular
 
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
Default

Not the best but this will find the next empty cell in column B and returns the Row number of the cell previous to an empty cell.

Dim MTCell As Range
Dim lrow
For Each MTCell In Range("B1:B10")
If MTCell = Empty Then
lrow = ActiveCell.Row - 1
'put your code here
End If
Next
SamS is offline   Reply With Quote
Old Mar 11th, 2002, 06:20 AM   #5
Guest
 
Posts: n/a
Default

Brilliant! Excuse my ignorance, I am extremely Excel illiterate! But...how do I get this bit of programming to return a value (true or false would do) to a specific cell when it finds the information it is looking for? I am using the Find method.

Cheers!
  Reply With Quote
Old Mar 11th, 2002, 07:43 AM   #6
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

How about:


Sub FoundIt
Dim bFound As Boolean
On Error Resume Next
bFound = Range("A11:B20").Find(What:="7", After:=Range("A11"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
On Error GoTo 0
Sheet1.Range("A1") = bFound
End sub

Dave Hawley is offline   Reply With Quote
Old Mar 11th, 2002, 08:06 AM   #7
Guest
 
Posts: n/a
Default

Ok, got that to work, thanks.

Is there any way it can now look for the column heading that I have set up and match that to a report number?

For example, if it finds a "7" in the column headed "4" can it return that true or false response to a cell in report "4"?

My spreadsheet looks a little like this...
1 2 3 4 5 6 7 8(Report Numbers)

1 3 4 5 7 2 5 (entries on s/sheet)
2
3

I really appreciate this, I'm learning loads!
  Reply With Quote
Old Mar 11th, 2002, 08:16 AM   #8
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Ok, here waht I THINK you want:


Sub FoundIt()
Dim bFound As Boolean
Dim strMyMatch As String
Dim strHead As String

'Value to compare a 5 rows down
strMyMatch = "Castle"
'Heading in row 1
strHead = Cells(1, 1)

On Error Resume Next
bFound = Range("A1:K1").Find(What:="7", After:=Range("A1"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Offset(5, 0) = strMyMatch
On Error GoTo 0

Cells(1, 1) = bFound
End Sub
Dave Hawley is offline   Reply With Quote
Old Mar 11th, 2002, 08:25 AM   #9
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default


I have a feeling you will want to loop through each heading.


Sub FoundIt()
Dim iCol As Integer
Dim strFind As String

'Loop through all headings to and match to 5 rows down
For iCol = 1 To WorksheetFunction.CountA(Range("A1:E1"))
strFind = Choose(iCol, "H1LookFor", "H2LookFor", _
"H3LookFor", "H4LookFor", "H5LookFor")
Cells(1, iCol) = (Cells(1, iCol).Offset(5, 0) = strFind)
Next iCol
End Sub
Dave Hawley is offline   Reply With Quote
Old Mar 11th, 2002, 08:30 AM   #10
Guest
 
Posts: n/a
Default

Couple of queries...

What does the bit about 'Value to compare a 5 rows down
strMyMatch = "Castle" mean? Should I see the word "castle" somewhere if it finds a 7?

Also what does Offset(5, 0) = strMyMatch mean?
  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:41 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