Consulting

Results 1 to 4 of 4

Thread: Create a border around a range for specific criteria

  1. #1

    Post Create a border around a range for specific criteria

    Hi all,

    I have a range of records and the number of rows down will grow or shrink dynamically depending on how much data has been inputted, so there is no set endpoint. The columns is also the same.

    Is there a way to generate an outline border around the entire range of cells include next rows used based on SA_START_DATE (at column O, AA, AM, and so on)?

    Current:
    2020-02-11_102605.jpg

    Expected results:
    2020-02-11_102721.jpg

    Have attached sample Excel with dummy data.
    macro_SA_20200211.xls

    Your ideas/ suggestions are welcome. Thanks for your help!

  2. #2
    After the trial-and-error pays off, I'm glad to share the following code which can solve this question with you all.

                    If Worksheets(WS).Cells(i, Col + 6).value = Worksheets(WS).Cells(i - 1, Col + 6).value Then
                        Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i, Col + 10).Address()).BorderAround LineStyle:=xlContinuous, Color:=vbCyan, Weight:=xlThick
                        Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i, Col + 10).Address()).Borders(xlEdgeTop).LineStyle = xlContinuous
                        Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i, Col + 10).Address()).Borders(xlEdgeTop).Color = vbBlack
                        Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i, Col + 10).Address()).Borders(xlEdgeTop).Weight = xlThin
                        ' Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i + 1, Col + 10).Address()).Borders(xlInsideHorizontal).LineStyle = xlNone
                    Else
                        Worksheets(WS).Range(Cells(i, Col).Address(), Cells(i, Col + 10).Address()).BorderAround LineStyle:=xlContinuous, Color:=vbCyan, Weight:=xlThick
                    End If

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    That snippet could also be:
    With Worksheets(WS).Cells(i, Col).Resize(, 11)
      .BorderAround LineStyle:=xlContinuous, Color:=vbCyan, Weight:=xlThick
      If .Cells(7).Value = .Cells(7).Offset(-1).Value Then
        With .Borders(xlEdgeTop)
          .Color = vbBlack
          .Weight = xlThin
        End With
      End If
    End With
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Thanks! More condensed

    Quote Originally Posted by p45cal View Post
    That snippet could also be:
    With Worksheets(WS).Cells(i, Col).Resize(, 11)
      .BorderAround LineStyle:=xlContinuous, Color:=vbCyan, Weight:=xlThick
      If .Cells(7).Value = .Cells(7).Offset(-1).Value Then
        With .Borders(xlEdgeTop)
          .Color = vbBlack
          .Weight = xlThin
        End With
      End If
    End With

Tags for this Thread

Posting Permissions

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