+ Reply to Thread
Results 1 to 6 of 6

VBA - highlight cels

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    Metro Detroit
    MS-Off Ver
    Excel 2007
    Posts
    18

    VBA - highlight cels

    I am trying to write a macro to determine if holes are too close together. On the attached file, why are rows 8-11 all highlighted? Where did I go wrong? Only lines 8 and 10 should be highlighted.
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA - highlight cels

    Hi, tajennens,

    either clear the formatting prior to running the macro or use an If-Else-Statement to color/uncolor the cells?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-31-2012
    Location
    Metro Detroit
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: VBA - highlight cels

    I'm a litte confused. I cleared the formatting. Then I run the macro and it highlights rows 8-11 when it should only be highlighting rows 8 and 10. There is already an if statement to highlight.

  4. #4
    Registered User
    Join Date
    08-31-2012
    Location
    Metro Detroit
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: VBA - highlight cels

    I've got it working now. Thanks!

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA - highlight cells

    Hi, tajennens,

    do you mind sharing your solution?

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    08-31-2012
    Location
    Metro Detroit
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: VBA - highlight cels

    Instead of having two different IF statements, I combined them with an AND and it seems to be working now.

    If a <> b And Hypotenuse(Cells(a, 18), Cells(b, 18), Cells(a, 19), Cells(b, 19)) < Largest_Diameter(Cells(a, 24), Cells(b, 24)) Then

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1