Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Shading cells with If statements

Does anyone know how I can shade certain cells in by typing in a letter or
number, using If statements?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Shading cells with If statements

Try following in the worksheet module (right-click sheet tab view code)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim idx As Long

On Error GoTo errH
If Right$(Target(1), 2) = "##" Then
idx = Val(Target(1))
If idx < 1 Or idx 56 Then idx = xlAutomatic
Application.EnableEvents = False
Target(1).Interior.ColorIndex = idx

Target(1).ClearContents
End If

errH:
Application.EnableEvents = True
End Sub

Record a macro while formating cells with your favourite colours to get
colorindex's.

Type in your colorindex followed by "##". To clear colour format simply type
"##". (Obviously you could amend "##")

If you want this to work on all sheets, put similar code in the
"ThisWorkbook" module but you need to change the event as follows -

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)

'code

End Sub

Regards,
Peter T

"haifa" wrote in message
...
Does anyone know how I can shade certain cells in by typing in a letter or
number, using If statements?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Shading cells with If statements

Why don't you just use the
* Menu - Format - Conditional Formatting and
* set "Cell value is" "equal" "A"
* Hit the format button and choose whatever text/cell formatting you want

"haifa" wrote:

Does anyone know how I can shade certain cells in by typing in a letter or
number, using If statements?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Shading cells with If statements

change

If idx < 1 Or idx 56 Then idx = xlAutomatic


to
If idx < 1 Or idx 56 Then idx = xlNone

Peter T

"Peter T" <peter_t@discussions wrote in message
...
Try following in the worksheet module (right-click sheet tab view code)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim idx As Long

On Error GoTo errH
If Right$(Target(1), 2) = "##" Then
idx = Val(Target(1))
If idx < 1 Or idx 56 Then idx = xlAutomatic
Application.EnableEvents = False
Target(1).Interior.ColorIndex = idx

Target(1).ClearContents
End If

errH:
Application.EnableEvents = True
End Sub

Record a macro while formating cells with your favourite colours to get
colorindex's.

Type in your colorindex followed by "##". To clear colour format simply

type
"##". (Obviously you could amend "##")

If you want this to work on all sheets, put similar code in the
"ThisWorkbook" module but you need to change the event as follows -

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)

'code

End Sub

Regards,
Peter T

"haifa" wrote in message
...
Does anyone know how I can shade certain cells in by typing in a letter

or
number, using If statements?





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
Shading Rows With IF Statements? JPS Excel Worksheet Functions 5 October 15th 08 05:00 PM
Sum of all cells with red shading IndexTurret Excel Discussion (Misc queries) 4 November 27th 07 11:58 PM
shading used cells only mrharpo2u Excel Discussion (Misc queries) 4 June 26th 06 09:36 PM
Conditional Cell Shading (based on the shading of other cells) Tubby Excel Worksheet Functions 2 June 20th 06 10:03 PM
Shading Cells Charlie Birkett Excel Discussion (Misc queries) 1 January 6th 06 12:12 PM


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