#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 510
Default Formatting cells

Here is an example you can adapt to your specific situation :

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim i As Integer
Set Target = Range("b3")
If Target Is Nothing Then Exit Sub
'Clean whole sheet
Cells.Select
With Selection
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Range("B3").Select
'Adjusts to table
Select Case Target.Value
Case Is = "A"
i = 5
Case Is = "B"
i = 7
Case Is = "C"
i = 9
Case Is = "D"
i = 11
Case Is = "E"
i = 12
Case Is = "F"
i = 14
Case Is = "G"
i = 16
End Select

'Adjusts the table size
Range("D2:E" & i).Select

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("B3").Select

Application.ScreenUpdating = True
End Sub


HTH
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Cells amkake Excel Worksheet Functions 2 December 20th 06 04:14 AM
Formatting cells srinehart Excel Discussion (Misc queries) 1 May 2nd 06 09:16 PM
Formatting Cells longisland Excel Discussion (Misc queries) 3 September 20th 05 10:32 PM
Conditional Formatting Multiple cells based on 2 cells Louis Markowski Excel Worksheet Functions 2 June 1st 05 05:26 PM
Formatting Cells Randy Balch Excel Worksheet Functions 1 January 12th 05 06:25 PM


All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"