Solved: VBA in Excel: Automatically paint borders on data entry

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

maxx_eclipse

Thread Starter
Joined
May 28, 2007
Messages
291
Afternoon everyone!

I am trying to get a little bit of code working such that when a user enters in some data in column A, it triggers code in VBA to paint a simple surround black border over the whole row, from column A to M. Here is what I have so far, but it doesn't seem to be working. I know I am missing something (if not a lot).

Code:
Dim i As String

If ActiveCell.Column = 1 Then
	If ActiveCell.Value <> "" Then
	Range(Cells(i, 1),Cells(i, 13)).Borders.LineStyle = Excel.xlLineStyle.xlContinuous
	Else
	End
Else
End
I appreciate any help! Thank you in advance!
 

Keebellah

Trusted Advisor
Joined
Mar 27, 2008
Messages
6,611
First Name
Hans
Hi Maxx, you shouldn't forget to mention the version of Excel you're using

Place this code in the sheet

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column <= 13 Then
    If Target.Value <> "" Then
    Range("A" & Target.Row & ":M" & Target.Row).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Target.Offset(0, 1).Select
    End If
End If
End Sub
 

maxx_eclipse

Thread Starter
Joined
May 28, 2007
Messages
291
Hey Keebelleh, thanks for the reply and sorry for the late response; I have been away from my computer these past few days.

I will test the code soon and let you know if I am having any issues.

I forgot to mention I use Excel 2010.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top