0

I am trying to create a code to iterate over an excel document. I want the macro to highlight all rows based on the value to the left of the cell I am checking. This is what I'm trying to say, but can't properly in code.

For x = 4 to 3918
    if (x,2) contains the letters "LW" then
        look at (x,1)
        highlight all rows with value = (x,1) green

Please help, thank you.

2
  • 1
    If you know the logic, coding is cakewalk... Commented Jun 27, 2016 at 19:11
  • 1
    it can be done with conditional formatting, is vba a requirement? Commented Jun 27, 2016 at 19:15

1 Answer 1

1

While I can't be sure, I believe you want to translate your pseudocode like so

for x = 4 to 3918
    if Instr(cells(x, 2), "LW") then
        numToFind = cells(x, 1)
        for y = 4 to 3918
            if cells(y, 1) = numToFind then
                cells(y, 1).entirerow.Interior.ColorIndex = 4
            end if
        next y
    end if
next x

Am I reading you right?

Sign up to request clarification or add additional context in comments.

8 Comments

I tried this code. It is close in that it highlights all the rows with the "LW" in (x,2). However, it does not read the cell to the left of (x,2), find all rows with value (x,1) and highlight those cells.
@ROCKYIII find all rows with value (x,1) makes no sense given that x changes...
@ROCKYIII You want to find all rows with value (x,1). Can that value be anywhere in a row?
I'm sorry, I'm new. What I meant is, look 1 cell left of the cell with "LW" in it. That will have a value like "33" for example. Find all rows with that "33" and highlight them green.
@RockyIII Where else should we look for that value of 33? Where in the row? Anywhere in the row or in a particular column?
|

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.