Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding something not definite

Status
Not open for further replies.

icdastar

Technical User
Nov 16, 2004
12
US
Hi

I'm trying to build a macro that will find a string, but the string can be 5 different things. So how do I get it to find the cell that contains this information and use the information to paste in another cell. Below is the code I have that keeps getting me an error:

Dim Space As String
Let Space = " "
Dim Fast, Food, Snack, Candy, Groceries,
Retail,Beverages As String
Dim FF As Variant
Let FF = Fast & Space & Food
Dim RB As Variant
Let RB = Retail & Space & Beverages
Dim c As Range
c = m.Find(FF Or Snack Or Candy Or Groceries Or RB)
'm is the current region defined earlier in my code
Sheets("Instructions").Select
Dim t As Range
Let t = Range("A72:B76")
Let A.Offset(0, -4) = t.Find(c).Offset(0, 1).Value
'A is an activecell range defined earlier.


If anyone could help me figure this out that would be great! Thanks! Happy Thanksgiving everyone!
 
Hi,

1. You never assigned any VALUES to your variables

2. You cannot use OR in a FIND function

3. Objects must be Set

Something like this might work...
Code:
    Dim FoodItems(1 To 5)
    FoodItems(1) = "Fast Food"
    FoodItems(2) = "Retail Beverages"
    FoodItems(3) = "Snack"
    FoodItems(4) = "Candy"
    FoodItems(5) = "Groceries"
    Dim c As Range
    Dim t As Range
    Set t = Sheets("Instructions").Range("A72:B76")
    For i = 1 To 5
        Set c = m.Find(FoodItems(i))
        If Not c Is Nothing Then
            A.Offset(0, -4).Value = t.Find(c.Value).Offset(0, 1).Value
        End If
    Next

Skip,
[sub]
[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top