0

I have cells that are either "True" or "False". I have names for these cells so that it's easier for me to reference in my codes. For Example, instead of saying cell "A1" I say cell "Apples". The cell names are:
Apples
Oranges
Onions
Potatoes
Bananas

In a separate worksheet I have under column A:
Apples
Oranges
Bananas
This range of cells is named "Fruit". So this list is meant to be a list of the cell names I want to check.

I want to use a for loop to check if each cell referenced under in the range "Fruit" is true. This is my code:

For Each item In [Fruit]
    If Worksheets("Inventory").Range(item).Value = True Then
        --Do stuff--
    End If
Next item

I keep getting an error when trying to reference the cell. How can I do this? Is it possible for me to use the counter to reference the cell?

1 Answer 1

1

close...

For Each item In [Fruit]
    If Worksheets("Inventory").Range(item.Value) = True Then
        '--Do stuff--
    End If
Next item
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.