0

I searched the boards, but wasn't able to find any old posts that helped me with this. I think the solution is probably simple, but I just can't seem to come up with the correct format.

I need to write a VBA macro that will loop through a specific column (K) and highlight any date that is less than a date that I entered in a set cell (A1 in this case). The date is variable so it could change. Any help or direction would be great!

2
  • 4
    Why not use Conditional Formatting? Commented Aug 7, 2017 at 22:06
  • conditional formatting can be finicky if you're constantly deleting and adding rows. I've ended up with sheets where some had the conditional formatting rule and others didn't. Commented Aug 7, 2017 at 22:32

1 Answer 1

1

As Scott Craner mentioned, you can use Conditional Formatting. Under Home > Conditional Formatting, you can create a rule doing the following:

  1. Select the range you want to apply the formatting
  2. Click Home > Conditional Formatting > New Rule and "Use a Formula to determine which cells to format"
  3. in the formula box enter =K2<$A$1 - In this example K2 is the first cell in the range you select. The Dollar signs make the A1 range absolute so it doesn't change to A2, A3 etc as it goes through the range.
  4. Click Format and set the format for how you want those cells to appear
Sign up to request clarification or add additional context in comments.

5 Comments

Formula would be: =K2<$A$1
That's bizarre, that's what I wrote but the comment didn't seem to display properly. if I change the $ before A to £ it all shows, but omitted or left as $ it stops the line after K2!
Just figured it out - it didn't like the lack of spaces in the formula, must have been reading it as some kind of tag due to the "<".
Thanks! That seems to help a lot.
Thanks Ryan, can you mark it as an accepted answer if it gives you what you need? If not, let me know what else you need. I'm trying to increase my rep on this site :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.