Solved

# Conditionally draw border with VBA

Posted on 2013-06-20
Medium Priority
423 Views
Have an excel question (version 2010) as follows. For example, 2 columns and 7 rows

A     B
1      Key  Value
2      D1   10
3              20
4      E1    11
5              21
6              31
7      F1    22
would like to draw the border (all solid lines around the cells, only draw the bottom lines as an example), but if there are no values in column A, do not draw anything, simply take the defaults.

A     B
1      Key  Value
--------------------
2     D1   10
3             20
--------------------
4     E1    11
5             21
6             31
--------------------
7     F1   22
--------------------

Wrote something like this

Sub T()

With Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

How to add the check cell condition statement?
0
Question by:jl66
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 81

Accepted Solution

byundt earned 2000 total points
ID: 39264874
You might try a macro like this:
``````Sub T()
Dim rw As Range
With Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row)
With .Borders
.LineStyle = xlOutline
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
For Each rw In .Rows
If rw.Cells(2, 1).Value <> "" Then
With rw.Borders(xlEdgeBottom)
.LineStyle = xlDash
End With
End If
Next
End With
End Sub
``````
0

Author Closing Comment

ID: 39265713
Thanks a lot.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
###### Suggested Courses
Course of the Month10 days, 23 hours left to enroll