Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default worksheet_change colour of a row on change of cell

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default worksheet_change colour of a row on change of cell

Peta,

You can't step into a function, or a subroutine that takes parameters. Try
this one out to change the color of a row when the selection is changed.

Dim lPreviousRow As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
Rows(lPreviousRow).Interior.ColorIndex = xlNone
lPreviousRow = Target.Row
End If
End Sub




"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default worksheet_change colour of a row on change of cell

Vergel

thanks - I changed your code slightly to just a change event & it coloured
it ok but I got a run-time error 1004: Application defined or object defined
error at line
Rows(lPreviousRow).Interior.ColorIndex = xlNone

"Vergel Adriano" wrote:

Peta,

You can't step into a function, or a subroutine that takes parameters. Try
this one out to change the color of a row when the selection is changed.

Dim lPreviousRow As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
Rows(lPreviousRow).Interior.ColorIndex = xlNone
lPreviousRow = Target.Row
End If
End Sub




"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default worksheet_change colour of a row on change of cell

Peta,

Change this line:

Rows(lPreviousRow).Interior.ColorIndex = xlNone

to become like this:

If lPreviousRow < 0 then
Rows(lPreviousRow).Interior.ColorIndex = xlNone
End If


"Peta" wrote:

Vergel

thanks - I changed your code slightly to just a change event & it coloured
it ok but I got a run-time error 1004: Application defined or object defined
error at line
Rows(lPreviousRow).Interior.ColorIndex = xlNone

"Vergel Adriano" wrote:

Peta,

You can't step into a function, or a subroutine that takes parameters. Try
this one out to change the color of a row when the selection is changed.

Dim lPreviousRow As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
Rows(lPreviousRow).Interior.ColorIndex = xlNone
lPreviousRow = Target.Row
End If
End Sub




"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default worksheet_change colour of a row on change of cell

For debugging add this function into the VBA. Your code doesn't run because
VBA doesn't recognized that Worksheet_Change requires parameter.

Main subroutines that are called from an excel spreadsheet cannot contain
parameters. Only secondarty subroutines can have parameters. subroutine
also cannot return parameters.

Functions can be have parameters and return values, but cannot write to
excel spreadsheets.

Beginners often havve these problems.

Sub abc()

Set myRange = Range("A1:D5")

Worksheet_Change (myRange)

End Sub

"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default worksheet_change colour of a row on change of cell

Joel

I inserted your suggestion and came up with a run-time error 424 - object
required
Dim lPreviousRow As Long
Dim myrange As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Set myrange = Range("A1:N25")
Worksheet_Change (myrange)
If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
Rows(lPreviousRow).Interior.ColorIndex = xlNone
lPreviousRow = Target.Row
End If
End Sub


"Joel" wrote:

For debugging add this function into the VBA. Your code doesn't run because
VBA doesn't recognized that Worksheet_Change requires parameter.

Main subroutines that are called from an excel spreadsheet cannot contain
parameters. Only secondarty subroutines can have parameters. subroutine
also cannot return parameters.

Functions can be have parameters and return values, but cannot write to
excel spreadsheets.

Beginners often havve these problems.

Sub abc()

Set myRange = Range("A1:D5")

Worksheet_Change (myRange)

End Sub

"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default worksheet_change colour of a row on change of cell

Petra: This is the code I used to debug the problem. there is a problem when
the row i1 th eprevious row is then 0. the macro was failing because row 0
doesn't exist.

Dim lPreviousRow As Long
Sub test_macro()
Set myrange = Range("A1:N25")
Worksheet_Change (myrange)

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
If lPreviousRow < 0 Then
Rows(lPreviousRow).Interior.ColorIndex = xlNone
End If
lPreviousRow = Target.Row
End If
End Sub



"Peta" wrote:

Joel

I inserted your suggestion and came up with a run-time error 424 - object
required
Dim lPreviousRow As Long
Dim myrange As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Set myrange = Range("A1:N25")
Worksheet_Change (myrange)
If lPreviousRow < Target.Row Then
Target.EntireRow.Interior.Color = vbBlue
Rows(lPreviousRow).Interior.ColorIndex = xlNone
lPreviousRow = Target.Row
End If
End Sub


"Joel" wrote:

For debugging add this function into the VBA. Your code doesn't run because
VBA doesn't recognized that Worksheet_Change requires parameter.

Main subroutines that are called from an excel spreadsheet cannot contain
parameters. Only secondarty subroutines can have parameters. subroutine
also cannot return parameters.

Functions can be have parameters and return values, but cannot write to
excel spreadsheets.

Beginners often havve these problems.

Sub abc()

Set myRange = Range("A1:D5")

Worksheet_Change (myRange)

End Sub

"Peta" wrote:

Hi - can anyone help please
I've tried Subject: More than 6 conditional Formats....VBA Coding Advise
please 1/5/2006 7:08 PM PST

By: JulieD In: microsoft.public.excel.newusers

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err_Handler

If Not Intersect(Target, Range("K1:K20")) Is Nothing Then
Application.EnableEvents = False
i = Target.Row
Select Case Target.Value
Case "Yes"
Range("A" & i & ":M" & i).Interior.ColorIndex = 6
Case "No"
Range("A" & i & ":M" & i).Interior.ColorIndex = 12
Case "W"
Range("A" & i & ":M" & i).Interior.ColorIndex = 18
Case "X"
Range("A" & i & ":M" & i).Interior.ColorIndex = 22
Case "Y"
Range("A" & i & ":M" & i).Interior.ColorIndex = 26
Case "Z"
Range("A" & i & ":M" & i).Interior.ColorIndex = 30
Case Else
Range("A" & i & ":M" & i).Interior.ColorIndex = xlNone
End Select
End If

Err_Handler:
Application.EnableEvents = True
End Sub

but doesn't work - I'm using XP - Excel 2003
it won't even debug - step into

any suggestion welcome
thanks

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
worksheet_change colour of a row on change of cell Mike Excel Programming 0 February 23rd 07 12:54 PM
Recognizing cell change in a Sub Worksheet_Change procedure Dave Peterson Excel Programming 3 December 30th 06 11:18 PM
Recognizing cell change in a Sub Worksheet_Change procedure Gary''s Student Excel Programming 0 December 29th 06 07:39 PM
Using worksheet_change to change value of target cell?? [email protected] Excel Programming 2 June 19th 06 04:59 PM
change a cell background colour to my own RGB colour requirements Stephen Doughty Excel Discussion (Misc queries) 4 June 16th 06 01:08 PM


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