VBA to insert .xlborder if cell value not equal to previous cell

F

Forgone

I've got a worksheet and I'm wondering whether it is possible to
insert a line when a value in Column A, B, C & D does not equal the
values in the row above or below it.

I've currently got a formula in Column A that reads....
=IF(AND(B3=B2,C3=C2,D3=D2,E3=E2),"","IL") and a conditional format
that if the cell value is equal to "IL" then put a border. Wondering
if there is a better way to do this via VBA or is that the better way?
 
X

xyz xyz2

I've got a worksheet and I'm wondering whether it is possible to
insert a line when a value in Column A, B, C & D does not equal the
values in the row above or below it.

I've currently got a formula in Column A that reads....
=IF(AND(B3=B2,C3=C2,D3=D2,E3=E2),"","IL") and a conditional format
that if the cell value is equal to "IL" then put a border.  Wondering
if there is a better way to do this via VBA or is that the better way?

'*********************************************************************

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

With Me

If .Range("B2").Value = .Range("B3").Value _
And .Range("C2").Value = .Range("C3").Value _
And .Range("D2").Value = .Range("D3").Value _
And .Range("E2").Value = .Range("E3").Value _
Then

..Range("A1").Value = "IL"
..Range("A1").Borders.Color = 3

Else

..Range("A1") = ClearContents
..Range("A1").Borders.LineStyle = xlLineStyleNone

End If

End With

End Sub

'*********************************************************************
 
S

Steve Dunn

In your conditional formatting formula, instead of

=A1="IL"

(which I assume is what you've got)

Use:

=OR(B3<>B2,C3<>C2,D3<>D2,E3<>E2)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top