I have been looking everywhere for an example on how to apply+ borders to all cells in a worksheet with text.
I pull reports from a program and sometimes there are blank cells throughout the row. Currently I have to manually highlight all cells with text and press the border button. It would save a lot of time if I could just run a macro that would put borders around all cells that have text.
Is this possible?
Thank you!
Last edited by VBA Noob; 01-22-2009 at 12:57 PM.
This will put borders around each individual cell that has text. Is that what you are looking for?
HTHSub DrawBorders() With Cells.SpecialCells(xlCellTypeConstants, 23) .BorderAround xlContinuous, xlThin, xlColorIndexAutomatic On Error Resume Next 'used in case there are no inside borders With .Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With .Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End With End Sub
Jason
Jason,
Thanks for the quick reply. When I ran the macro it formatted every cell from left to right that had text in that row.
Here is an example of the spreadsheet I have:
Text are in the following cells:
A1 B1 C1 D1
D2
B3 D3
I am just looking for those cells to receive the borders. I do not want borders in the others (i.e.A2, A3, B2)
Can you post up an example copy of your workbook so I can take a look at it?
Here is an example of the worksheet after I format it.
Ok, so in your example, what did you expect to accomplish? Do you want borders only in cells that have letters? Or only that have words? Please be more specific in exactly what you are looking for.
I need the macro to put borders around all cells with text inside. Just like how I have the borders formatted in the sample worksheet I sent you. If the cell does not have text, it does not get a border. If it has text it gets a border.
The issue is that several of the cells have spaces in them. So you first need to get rid of those, then apply the borders. Try:
HTHSub DrawBorders() Dim Cell As Range For Each Cell In Cells.SpecialCells(xlCellTypeConstants, xlTextValues) If Left(Cell, 2) = " " Then Cell.ClearContents Next Cell With Cells.SpecialCells(xlCellTypeConstants, 23) .BorderAround xlContinuous, xlThin, xlColorIndexAutomatic On Error Resume Next 'used in case there are no inside borders With .Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With .Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End With End Sub
Jason
Thanks for the help. You saved me a lot of time.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks