Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Macro formats field with value

This may be kindda easy but for some reason I can't figure it out.

I have a Macro that formats multiple sheets within the same workbook.
Everything is working great but there is one last step I'd like to do and I'm
not certain on how to accomplish it.

If the Cell has contents I would like the Cell to have a border on all four
sides but only if the Cell has some content, any content, a number, text,
anything, it doesn't really matter. I'm having difficulties getting this into
a Macro.

Any suggestions would be great. Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Macro formats field with value

Hi,
You can use COnditionalFormatting feature to set a general conditional
format to the entire range.
Eg: range A1:A100
''' -----------------------------------------------
Sub SetCondFormat()
Dim rg As Range

Set rg = Range("A1:A100")
rg.Select

With rg.FormatConditions

.Delete
.Add Type:=xlExpression, Formula1:= _
"=" & rg.Cells(1).Address(False, False) & "<"""""

With .Item(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Item(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Item(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Item(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub
'''-----------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"FrankM" wrote:

This may be kindda easy but for some reason I can't figure it out.

I have a Macro that formats multiple sheets within the same workbook.
Everything is working great but there is one last step I'd like to do and I'm
not certain on how to accomplish it.

If the Cell has contents I would like the Cell to have a border on all four
sides but only if the Cell has some content, any content, a number, text,
anything, it doesn't really matter. I'm having difficulties getting this into
a Macro.

Any suggestions would be great. Thank you!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Macro formats field with value

Frank, a macro isn't even needed for this. Conditional formatting will do the
trick, and you should be able to use the macro recorded to get your macro to
automatically add the conditional formatting. Here are the steps to make a
selection of cells, assuming the top left selected cell is A1, have a border
if the cell is not empty:

Select Cells
Goto: Format... Conditional Formatting
Select the "Cell Value Is" Drop down box and choose "Formula Is"
Type this in the TextBox: =A1<""
Click the "Format" button
Select the "Border" tab
Choose the border you wish to have if the cell is not empty
Click "Ok"
Click "Ok" again

That's it. Let me know if you have problems or need helping getting the
macro recorder to work with this.
--
Charles Chickering

"A good example is twice the value of good advice."


"FrankM" wrote:

This may be kindda easy but for some reason I can't figure it out.

I have a Macro that formats multiple sheets within the same workbook.
Everything is working great but there is one last step I'd like to do and I'm
not certain on how to accomplish it.

If the Cell has contents I would like the Cell to have a border on all four
sides but only if the Cell has some content, any content, a number, text,
anything, it doesn't really matter. I'm having difficulties getting this into
a Macro.

Any suggestions would be great. Thank you!

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
macro to copy formats shaji Excel Discussion (Misc queries) 1 February 19th 10 02:25 PM
Copying formats - column widths, formats, outlining to worksheets DavidBr318 Excel Worksheet Functions 4 August 14th 09 05:03 AM
More than 3 conditional formats or a macro? rstruhs Excel Programming 1 August 1st 07 03:48 PM
a macro that Formats a textbox based on value in a cell txm49 Excel Worksheet Functions 1 June 6th 07 02:36 PM
Macro to Find Cells with Conditional Formats John Franklin Excel Programming 6 September 1st 04 11:53 PM


All times are GMT +1. The time now is 10:21 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"