Using VBA code: add Borders if Conditions Met

Closed
Josh - Feb 28, 2012 at 03:30 PM
 Josh - Feb 29, 2012 at 09:39 AM
Hello,

I am at the very beginning stages of trying to learn VBA in Excel 2007.

I am trying to merge some cells in the next row, and I would like to add a border around a set of cells in that row. (A14:L14)

Here is the VBA code I have for the merging portion (thanks to shg from http://www.excelforum.com/excel-general/700158-conditional-merge.html)
---------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$13" Then
With Range("B14:F14")
If IsEmpty(Target.Value) = False Then
.Merge
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
Else
.UnMerge
.Offset(1)(1).Select
End If
End With
End If
End Sub
-----------------------------------------------------------------------------

Any help would definately be appreciated.
Then to top this off, I am going to want to repeat this for 50 lines as data is entered into column B. So, if I could be pointed in the right direction for that, I would appreciate it as well.

Thank you,
Josh

Related:

1 response

Figured it out. But, now I would like to extend this to happen every time there is something entered in the next row in columb B. If any help can be given, I would appreciate it.
Thank you,
Josh

_____________________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$13" Then
With Range("B14:F14")
If IsEmpty(Target.Value) = False Then
.Merge
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
Range("A14:L14").Borders.LineStyle = xlContinuous
.Select
Else
Range("A14:L14").Borders.LineStyle = xlLineStyleNone
.UnMerge
.Offset(1)(1).Select
End If
End With
End If
End Sub
______________________________________________________
0