Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2010, 08:43 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Draw cell borders

Hi,

How should I code in Macro Excel 2007, for cells contains with data which selected below with top, bottom, left and right borders.


Sub resolved()
'Range("A2:J1000").Sort Key1:=Columns("D"), Order1:=xlAscending, Key2:=Columns("H"), Order2:=xlAscending
Range("A:A,D:E,G:I").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Columns.AutoFit
End With

Range("B:C,F:F,J:J").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.Columns.AutoFit
End With

End Sub
 
Old November 26th, 2010, 09:11 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts
Default Use the macro recorder

Just use the macro recorder and that should give you the code to get started
 
Old November 26th, 2010, 09:14 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts
Default Here's code from Macro recorder

here's the code i got using the macro recorder:

Code:
    Range("C1").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlMedium
    End With
Hope that helps.
 
Old November 26th, 2010, 11:14 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for reply mtranchi,

Yours draw borders for all cells selected in sheet by range.

Anyway I just want to draw top, bottom, left and right borders for cells selected contains with data only in my sheet and not for all cells selected in sheet by range.
 
Old November 26th, 2010, 11:18 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for add up, for each cells selected contains with data .





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you create borders around text? andypandyrox456 BOOK: Beginning HTML, XHTML, CSS, and JavaScript 8 April 4th, 2010 07:12 PM
How to paste the text from a cell without its borders? bacoms Excel VBA 2 September 29th, 2009 05:34 PM
'Table' does not contain a definition for 'BorderS AccessAasif@aol.com C# 2005 1 September 13th, 2008 03:08 AM
How to: Have no borders and stuff! Apocolypse2005 Beginning VB 6 7 May 8th, 2007 11:56 AM
table borders scud-murphy Dreamweaver (all versions) 1 June 6th, 2006 12:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.