Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format cell if contains a value

Hi, all

How would I (at the click of an activeX button) format cells wit
borders and make the cells fill colour white if it has a value in it?

Cheers,
Simon

B.T.W
Thanks for all your help for a newbi

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Format cell if contains a value

Assume by value you mean the cell is not blank or does not appear blank.

for each cell in ActiveSheet.Cells.SpecialCells(xlformulas)
if cell< "" then
cell.BordersAround ColorIndex:=1, Weight:=xlThick
cell.Interior.ColorIndex = 2
end if
Next
for each cell in ActiveSheet.Cells.SpecialCells(xlConstants)
if cell< "" then
cell.BordersAround ColorIndex:=1, Weight:=xlThick
cell.Interior.ColorIndex = 2
end if
Next

--
Regards,
Tom Ogilvy


"sjbeeny " wrote in message
...
Hi, all

How would I (at the click of an activeX button) format cells with
borders and make the cells fill colour white if it has a value in it?

Cheers,
Simon

B.T.W
Thanks for all your help for a newbie


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Format cell if contains a value

Try something like the following:

Private Sub CommandButton1_Click()
Dim Rng As Range
For Each Rng In Range("A1:C10") '<<< CHANGE
If Rng.Value < "" Then
Rng.BorderAround xlSolid, xlMedium
Rng.Interior.Color = RGB(255, 255, 255)
End If
Next Rng
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"sjbeeny " wrote in
message ...
Hi, all

How would I (at the click of an activeX button) format cells

with
borders and make the cells fill colour white if it has a value

in it?

Cheers,
Simon

B.T.W
Thanks for all your help for a newbie


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Format cell if contains a value

my typo,
BordersAround should be BorderAround (singular)

for weight you can do xlMedium or xlThin as well

Also, specialcells will raise an error if it doesn't find cells to satisfy
the condition, so you can suppress that with

Sub ApplyBorders()
On Error Resume Next
For Each cell In ActiveSheet.Cells.SpecialCells(xlFormulas)
If cell < "" Then
cell.BorderAround ColorIndex:=1, Weight:=xlMedium
cell.Interior.ColorIndex = 2
End If
Next
For Each cell In ActiveSheet.Cells.SpecialCells(xlConstants)
If cell < "" Then
cell.BorderAround ColorIndex:=1, Weight:=xlMedium
cell.Interior.ColorIndex = 2
End If
Next
On Error GoTo 0
End Sub

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Assume by value you mean the cell is not blank or does not appear blank.

for each cell in ActiveSheet.Cells.SpecialCells(xlformulas)
if cell< "" then
cell.BordersAround ColorIndex:=1, Weight:=xlThick
cell.Interior.ColorIndex = 2
end if
Next
for each cell in ActiveSheet.Cells.SpecialCells(xlConstants)
if cell< "" then
cell.BordersAround ColorIndex:=1, Weight:=xlThick
cell.Interior.ColorIndex = 2
end if
Next

--
Regards,
Tom Ogilvy


"sjbeeny " wrote in message
...
Hi, all

How would I (at the click of an activeX button) format cells with
borders and make the cells fill colour white if it has a value in it?

Cheers,
Simon

B.T.W
Thanks for all your help for a newbie


---
Message posted from http://www.ExcelForum.com/





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format cell if contains a value

A few variations, especially if you like one-liners:

Sub HighlightAllNumbers()
On Error Resume Next
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants
xlNumbers).Interior.ColorIndex = 6
End Sub

Sub HighlightAllText()
On Error Resume Next
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants
xlTextValues).Interior.ColorIndex = 7
End Sub

Sub UndoAllHighlights()
On Error Resume Next
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants ).Interior.ColorInde
= 0
End Sub

Sub ShowColorPalette()
For x = 1 To 56
With ActiveCell 'starts at current cell
.Offset(0, 0) = x
.Offset(0, 1).Interior.ColorIndex = x
.Offset(1, 0).Select
End With
Next
End Sub

Regards,
billy

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format cell if contains a value

Wow, Thanks for all the responses guys

Tom, I was wondering if I could limit your formulae to a specific rang
in some manner. I should have been more clear when I first asked th
question but I only want to reformat the new cells entered in range
"TitleInvoice","PriceInvoice" and "TotalInvoice" I used your formula
and it worked a little too well and changed the format of all cell
(Headings etc.)

Chip, I tried using your procedure except I changed the range to th
above ("TitleInvoice","PriceInvoice" and "TotalInvoice") but for som
reason I got an error debug msg I will look further into it.

Billyb thanks for the suggestions I am yet to have a play around wit
them but will do tonight.

Thanks for all the imput everyone!

Regards,
Simo

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Format cell if contains a value

You can replace
ActiveSheet.Cells.

with any valid multiple cell reference and it will work only within that
reference.

BillyB's suggestion is really just an extension of the specialcells method I
suggested. So you should get similar results if you use Activesheet.Cells
except that he only uses the constants part of my suggestion.

--
Regards,
Tom Ogilvy

"sjbeeny " wrote in message
...
Wow, Thanks for all the responses guys

Tom, I was wondering if I could limit your formulae to a specific range
in some manner. I should have been more clear when I first asked the
question but I only want to reformat the new cells entered in ranges
"TitleInvoice","PriceInvoice" and "TotalInvoice" I used your formulae
and it worked a little too well and changed the format of all cells
(Headings etc.)

Chip, I tried using your procedure except I changed the range to the
above ("TitleInvoice","PriceInvoice" and "TotalInvoice") but for some
reason I got an error debug msg I will look further into it.

Billyb thanks for the suggestions I am yet to have a play around with
them but will do tonight.

Thanks for all the imput everyone!

Regards,
Simon


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format cell if contains a value

I tried doing as you said with a test range and it didn't work, There
was no error or anything just nothing happened. Have I entered the
range incorrectly? I used the code:

Private Sub CommandButton1_Click()

On Error Resume Next
For Each cell In Range("test").SpecialCells(xlFormulas)
If cell < "" Then
cell.BorderAround ColorIndex:=1, Weight:=xlMedium
cell.Interior.ColorIndex = 2
End If
Next
For Each cell In Range("test").SpecialCells(xlConstants)
If cell < "" Then
cell.BorderAround ColorIndex:=1, Weight:=xlMedium
cell.Interior.ColorIndex = 2
End If
Next
On Error GoTo 0
End Sub

Cheers, Simon


---
Message posted from http://www.ExcelForum.com/

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format cell if contains a value

Thanks for the help people all works well now.


Cheers,
Simo

--
Message posted from http://www.ExcelForum.com

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
Lock Cell Format - Allow copy and paste of data without format change Chris12InKC Excel Worksheet Functions 2 May 9th 23 07:42 PM
cell format - remove cell format pattern without effecting colors Bas Excel Discussion (Misc queries) 1 March 23rd 09 02:54 PM
Can cell format come from and change with reference cell format jclouse Excel Discussion (Misc queries) 1 November 29th 06 03:20 AM
Excel Auto-Format cell to email format Please Help Me Excel Discussion (Misc queries) 1 March 23rd 06 05:15 PM
How do I copy data in single cell format to a merged cell format Paul Excel Discussion (Misc queries) 1 June 27th 05 11:00 AM


All times are GMT +1. The time now is 08:16 PM.

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

About Us

"It's about Microsoft Excel"