0

I'm trying to write a for loop that includes the following if statement:

...For x = 1 To lr:
       If Range("G" & 1) = "Complete" Then...

The problem is the string "Complete" is an option in a dropdown list from data validation in every cell in column G, and my if statement isn't recognizing it as true even if it's selected. How can I get it to recognize a value from a dropdown? Thanks!

0m3r
  • 12,286
  • 15
  • 35
  • 71
  • 4
    Can you [edit the question](https://stackoverflow.com/posts/53326186/edit) to include the actual code? If it's `If Range("G" & counter) = "Complete" Then`, it isn't "coming from the dropdown list" at all. – Comintern Nov 15 '18 at 19:02
  • Is the dropdown an ActiveX control? A Forms control? A data validation dropdown? How you'd get the dropdown's value differs very much depending on what type of control you're looking at. `Range("G" & counter)[.Value]` could be how you'd go about checking a cell's content, i.e. when the "dropdown" is merely an in-cell data validation dropdown. – Mathieu Guindon Nov 15 '18 at 19:48
  • 2
    Also, `counter` is going to be constant at every iteration of that loop. Did you mean to use `x`? – Mathieu Guindon Nov 15 '18 at 19:51
  • You need to set your listbox value as a variable. i.e. `Dim lbVal as long` `lbVal = Listbox1.Value`. So `For x = lbVal to lr` `If Range("G" & x) = "Complete"` Change the "Listbox1' to the name of your listbox. – GMalc Nov 15 '18 at 20:39
  • @MathieuGuindon It's an in-cell data validation. I was using a counter there for another purpose, but for the context of this question using x makes more sense so I updated it. – A. Huggler Nov 16 '18 at 20:09
  • @Comintern I edited the question to hopefully make more sense. – A. Huggler Nov 16 '18 at 20:11
  • Does this answer your question? [Return the selected text from a dropdown box](https://stackoverflow.com/questions/9578038/return-the-selected-text-from-a-dropdown-box) – Jeremy Thompson Apr 03 '20 at 01:20

0 Answers0