Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Business Applications
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Border Macro

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
04-Aug-2009, 12:44 PM #1
Solved: Border Macro
Hi,

Does anyone know the code for a macro to put borders around any cell with data in it? this needs to be the border which cover's the edge of every cell.

There are three sheets i need this for each sheet has data from column a to column N.

If you require anymore info please do ask.

Thanks

Ashley
Jubbaloo's Avatar
Computer Specs
Senior Member with 123 posts.
 
Join Date: May 2009
Location: Nottingham, UK
Experience: It depends
04-Aug-2009, 01:25 PM #2
I think the easiest way to achieve this is using conditional formatting - you can create a rule that has outside border on cell if not blank.

If 2007 the Highlight the cells you want affected (probably have to do it once per sheet)

Conditional Formatting (On the Home Tab) > New Rule > Format only cells that contain > Change the 'Cell Value' to 'No Blanks' > Click on Format > Borders > Outside Borders

This should achieve what you want.

Let me know if you are using a different version and/or it doesn't make sense,

Cheers
__________________
From the darkness.... There Came.... A Torch!
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
10-Aug-2009, 06:57 AM #3
Hi i have already set up the sheet to use 3 conditional formatting options for a RAG (red amber gree) status check. Can this be done using VB worksheet code? Any other suggestions?

Thanks
bomb #21's Avatar
Distinguished Member with 7,166 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
10-Aug-2009, 09:41 AM #4
In this case, just use the macro recorder.

Start the recorder, enter a "useful" name, click OK.

Press F5, click Special, select "Constants", click OK.

Select the "All borders" border option, click OK.

Click Stop Recording.

(then record another one for cells with formulas if you need to)
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
10-Aug-2009, 01:08 PM #5
Hi bomb,

appreciate the help. This will allow me to have boarders only around cells with data in? im working on xl2003

Thanks
Jubbaloo's Avatar
Computer Specs
Senior Member with 123 posts.
 
Join Date: May 2009
Location: Nottingham, UK
Experience: It depends
10-Aug-2009, 03:04 PM #6
Sorry im only just getting back to you

Code:
Sub Borders()

' Borders Macro

    Selection.SpecialCells(xlCellTypeConstants, 23).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    
    
    
End Sub
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
10-Aug-2009, 04:17 PM #7
thats cool is this just the code for border or does it include the code required to ensure borders only appear in cells with data in them?

thanks
Jubbaloo's Avatar
Computer Specs
Senior Member with 123 posts.
 
Join Date: May 2009
Location: Nottingham, UK
Experience: It depends
10-Aug-2009, 04:30 PM #8
It does it all, it selects cells with data and then applies the border to them
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
11-Aug-2009, 04:26 AM #9
Hi,

Works fine excaept the line of code .TintAndShade = 0 causes a debug error, when i remove this line though in all of the places it appears it then works fine.

I do have one issue with this though, the code seems to draw a border around all data. For example i have data in A34 and A35, it draws a border around both these cells (an outside border), i really require the all borders type, is this possible? What part of the code do i need to change?

Thanks you apart from that issue its perfect.
Excel-Hocam's Avatar
Computer Specs
Junior Member with 1 posts.
 
Join Date: Aug 2009
Location: Ankara
Experience: Advanced
11-Aug-2009, 07:50 AM #10
Hi Ashley,

you can simply modify the last two lines of Jubbaloo's beautiful macro by replacing "xlNone" by "xlContinuous". You should get exactly what you requested.

Kind regards,
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
12-Aug-2009, 12:03 PM #11
Thank you all i will now close the thread.
Closed Thread Bookmark and Share

Tags
excel, microsoft

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 03:30 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.