Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Object Required Error 424

I'm using the following code to identify when a cell in a specific range is
modified, and then to color some cells based on these results ( I don't use
conditional formatting because it only allows 3 conditions).
When all my case statements are directly in the Worksheet_Change event
handler, then all runs fine. As soon as I move the code to its own sub and
try passing the range in, I get an Object Required error pointing to the
FillCells (t) line. Any suggestions would be greatly appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Intersect(Target, Range("A3:A50"))
If t Is Nothing Then Exit Sub
FillCells (t)

End Sub

Public Sub FillCells(Target As Range)
Select Case Target
Case "X"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 15
End With
Next c
Case "P"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 6
End With
Next c
Case "L"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 45
End With
Next c
Case "D"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 50
End With
Next c
Case Else
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = xlColorIndexNone
End With
Next c
End Select

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Object Required Error 424

Jason,

The problem is that you have parentheses around the t when you
call FillCells. When VBA encounters parentheses in this context,
it evaluates the expression or object. Since the Value property
is the default property of a Range object, your code is executing
as if you wrote

FillCells t.Value

Simply remove the parentheses in the call to FillCells, and all
will be right with your world.

FillCells t



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



"Jason" wrote in message
...
I'm using the following code to identify when a cell in a
specific range is
modified, and then to color some cells based on these results
( I don't use
conditional formatting because it only allows 3 conditions).
When all my case statements are directly in the
Worksheet_Change event
handler, then all runs fine. As soon as I move the code to its
own sub and
try passing the range in, I get an Object Required error
pointing to the
FillCells (t) line. Any suggestions would be greatly
appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Intersect(Target, Range("A3:A50"))
If t Is Nothing Then Exit Sub
FillCells (t)

End Sub

Public Sub FillCells(Target As Range)
Select Case Target
Case "X"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 15
End With
Next c
Case "P"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 6
End With
Next c
Case "L"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 45
End With
Next c
Case "D"
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = 50
End With
Next c
Case Else
For c = 1 To 12
With Target(1, c)
.Interior.ColorIndex = xlColorIndexNone
End With
Next c
End Select

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Object Required Error 424

Thank you!
I guess jumping around languages will always end up in syntactical errors :)
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
Object Required Error Cody Excel Programming 14 August 23rd 05 12:31 AM
Object required error Peter Rump Excel Programming 5 August 15th 05 09:52 AM
Object required error broogle Excel Programming 7 March 21st 05 09:01 AM
Error: 424 Object required DavidM[_3_] Excel Programming 1 January 13th 05 03:23 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 09:05 AM.

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"