Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mo2 Mo2 is offline
external usenet poster
 
Posts: 34
Default shading cells trouble

I'm not very good with scripting.
this script automatically shades cells based on values that i enter.
The script runs every time i edit a value in a cell.
It checks about 300 rows in about 10 columns.
The problem is, it takes very long.

I dont really need to check every cell between the F column and P column.
how do i specify this code to only update the cell shading of
Cell F25:F324 , H25:H324, J25:J324, L25:L324, N25:N324, and P25:P324

OR
if its possible, instead of updating up to the last row of the those columns
specified,
how about the code only checks up to the row i am currently working on?


Another question i have is...
Before i start, i know what row i will be going up to.
can i specify this in some cell or pop up window, and have my script's
range automatically update to that row? (instead of up to row 324)?

TIA



Sub ColorCells()
Dim icolor As Integer
Dim c As Range
For Each c In Range("F25:F324", "P25:P323")
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 ' dark green
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 ' bright green
Case 3
icolor = 10 ' green
Case 4
icolor = 5 ' blue
Case 5
icolor = 48 ' gray
Case 6
icolor = 9 ' dark red
Case Is 6
icolor = 3 ' red
Case Else
icolor = 2
End Select

c.Interior.ColorIndex = icolor
Next c
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Dim c As Range

If Not Intersect(Target, Range("A25:P323")) Is Nothing Then
ColorCells
For Each c In Target
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 'shrug
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 'bright green
Case 3
icolor = 10 'green
Case 4
icolor = 5 'blue
Case 5
icolor = 48 'gray
Case 6
icolor = 9 'dark red
Case Is 6
icolor = 3 'red
Case Else
'whatever
End Select

c.Interior.ColorIndex = icolor
Next c
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default shading cells trouble

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Dim c As Range

If Not Intersect(Target, Range("A25:P323")) Is Nothing Then
if c.Value <"" then ' May speed up things a little
ColorCells
For Each c In Target
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 'shrug
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 'bright green
Case 3
icolor = 10 'green
Case 4
icolor = 5 'blue
Case 5
icolor = 48 'gray
Case 6
icolor = 9 'dark red
Case Is 6
icolor = 3 'red
Case Else
'whatever
End Select

c.Interior.ColorIndex = icolor
Next c
End If
end if
End Sub

"Mo2" wrote in message
...
I'm not very good with scripting.
this script automatically shades cells based on values that i enter.
The script runs every time i edit a value in a cell.
It checks about 300 rows in about 10 columns.
The problem is, it takes very long.

I dont really need to check every cell between the F column and P column.
how do i specify this code to only update the cell shading of
Cell F25:F324 , H25:H324, J25:J324, L25:L324, N25:N324, and P25:P324

OR
if its possible, instead of updating up to the last row of the those
columns
specified,
how about the code only checks up to the row i am currently working on?


Another question i have is...
Before i start, i know what row i will be going up to.
can i specify this in some cell or pop up window, and have my script's
range automatically update to that row? (instead of up to row 324)?

TIA



Sub ColorCells()
Dim icolor As Integer
Dim c As Range
For Each c In Range("F25:F324", "P25:P323")
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 ' dark green
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 ' bright green
Case 3
icolor = 10 ' green
Case 4
icolor = 5 ' blue
Case 5
icolor = 48 ' gray
Case 6
icolor = 9 ' dark red
Case Is 6
icolor = 3 ' red
Case Else
icolor = 2
End Select

c.Interior.ColorIndex = icolor
Next c
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Dim c As Range

If Not Intersect(Target, Range("A25:P323")) Is Nothing Then
ColorCells
For Each c In Target
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 'shrug
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 'bright green
Case 3
icolor = 10 'green
Case 4
icolor = 5 'blue
Case 5
icolor = 48 'gray
Case 6
icolor = 9 'dark red
Case Is 6
icolor = 3 'red
Case Else
'whatever
End Select

c.Interior.ColorIndex = icolor
Next c
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
Mo2 Mo2 is offline
external usenet poster
 
Posts: 34
Default shading cells trouble

hi umm
i dont know if i was meant to replace anything with anything, so i just
copied and pasted your code over mine

it gives me a
Run-Time error '91':
Object variable or With block variable not set

"Coza" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Dim c As Range

If Not Intersect(Target, Range("A25:P323")) Is Nothing Then
if c.Value <"" then ' May speed up things a little
ColorCells
For Each c In Target
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 'shrug
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 'bright green
Case 3
icolor = 10 'green
Case 4
icolor = 5 'blue
Case 5
icolor = 48 'gray
Case 6
icolor = 9 'dark red
Case Is 6
icolor = 3 'red
Case Else
'whatever
End Select

c.Interior.ColorIndex = icolor
Next c
End If
end if
End Sub

"Mo2" wrote in message
...
I'm not very good with scripting.
this script automatically shades cells based on values that i enter.
The script runs every time i edit a value in a cell.
It checks about 300 rows in about 10 columns.
The problem is, it takes very long.

I dont really need to check every cell between the F column and P column.
how do i specify this code to only update the cell shading of
Cell F25:F324 , H25:H324, J25:J324, L25:L324, N25:N324, and P25:P324

OR
if its possible, instead of updating up to the last row of the those
columns
specified,
how about the code only checks up to the row i am currently working on?


Another question i have is...
Before i start, i know what row i will be going up to.
can i specify this in some cell or pop up window, and have my script's
range automatically update to that row? (instead of up to row 324)?

TIA



Sub ColorCells()
Dim icolor As Integer
Dim c As Range
For Each c In Range("F25:F324", "P25:P323")
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 ' dark green
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 ' bright green
Case 3
icolor = 10 ' green
Case 4
icolor = 5 ' blue
Case 5
icolor = 48 ' gray
Case 6
icolor = 9 ' dark red
Case Is 6
icolor = 3 ' red
Case Else
icolor = 2
End Select

c.Interior.ColorIndex = icolor
Next c
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Dim c As Range

If Not Intersect(Target, Range("A25:P323")) Is Nothing Then
ColorCells
For Each c In Target
Select Case c
Case Is < 0
icolor = 3 'red
Case 0
icolor = 51 'shrug
Case 1
icolor = 45 'light orange
Case 2
icolor = 4 'bright green
Case 3
icolor = 10 'green
Case 4
icolor = 5 'blue
Case 5
icolor = 48 'gray
Case 6
icolor = 9 'dark red
Case Is 6
icolor = 3 'red
Case Else
'whatever
End Select

c.Interior.ColorIndex = icolor
Next c
End If

End Sub




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
Sum of all cells with red shading IndexTurret Excel Discussion (Misc queries) 4 November 27th 07 11:58 PM
Shading Cells Crazydad42 Excel Discussion (Misc queries) 1 November 10th 06 01:44 AM
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
Shading Cells Jeff Excel Worksheet Functions 1 May 3rd 05 11:18 PM


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