• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Conditional Bordering Code!

Jayce

New Member
In my sheet, I have non-empty and empty cells in Column A. I want to border around the cells in Column A prior to the next non-empty cells (please check End-Result Sheet of the attached workbook)
I am attaching a workbook with two sheets: Raw Sheet that needs coding and End-Result Sheet to see the results I am looking for.
 

Attachments

  • Border.xlsm
    10.1 KB · Views: 7
Hi Herofox,

This is not what I am looking for. You are just bordering non-empty cells. I want to create border around all the empty cells following a non-empty cell, for instance, A3:A6 because A4:A6 cells are empty
A8:A11 as A9:A11 are empty

If a non-empty cell is followed by non-empty cells, then I want to create a border around each non-empty cells cell. For eg, a border around A7 only
 
How about
Code:
Sub Jayce()
   With Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
      .SpecialCells(xlConstants).Borders.Weight = xlThin
      With .SpecialCells(xlBlanks)
         .Borders(xlEdgeTop).LineStyle = xlNone
         .Borders(xlEdgeBottom).Weight = xlThin
      End With
   End With
End Sub
 
Great Job, Fluff13

It's working pretty well.

Could you please add the comments in code, so that it becomes easy to understand the working of script
 
try this macro
Code:
Option Explicit
Sub BORDER_IT()
 With Range("a1").CurrentRegion
  .Borders.LineStyle = 0
    With .Columns(1).SpecialCells(2, 23)
     .Borders.LineStyle = 1
     .Offset(, 1).Borders.LineStyle = 1
    End With
 End With
End Sub
 
I want to create border around all the empty cells following a non-empty cell, for instance, A3:A6 because A4:A6 cells are empty
A8:A11 as A9:A11 are empty
I don't think VBA is needed to solve this problem.

I will add another CF condition (to the examples set by @herofox and @Peter Bartholomew) and the result is the same as using the VBA set by @Fluff13 btw. which is excellent.

This formula below, returns the row number of the last filled cell in the 'B' column.
Code:
Named formula: LastRow
References: =SUMPRODUCT(MAX(($B$1:$B$130<>"")*ROW($B$1:$B$130)))

Formula in the Conditional Formatting is below
Code:
=ROW()=LastRow

Another Conditional Formatting formula
=ISTEXT(A3) by the PB
or
=$A3<>"" by the Herofox
 

Attachments

  • jayce-navic-42640.xlsx
    51.7 KB · Views: 2
Great Job, Fluff13

It's working pretty well.

Could you please add the comments in code, so that it becomes easy to understand the working of script
You're welcome & thanks for the feedback.
Code:
Sub Jayce()
   With Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
      .SpecialCells(xlConstants).Borders.Weight = xlThin             'applies borders to all cells in col A that contain a value (other than formulae)
      With .SpecialCells(xlBlanks)                                   '"selects" all cells in col A that are blank
         .Borders(xlEdgeTop).LineStyle = xlNone                      'removes the top borders
         .Borders(xlEdgeBottom).Weight = xlThin                      'applies a bottom border
      End With
   End With
End Sub
 
Back
Top