Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem with Nothing command

Hi I am struggling with a Nothing command.

If I have a cell that has a dependent, the background colour should
not be changed, whereas the colour should be changed if the cell lacks
dependents.

However, as it is now the macro changes the value irregardless. When
my container takes on a value (i.e is NOT nothing) it should not
proceed with the .interior command, but yet it does. Any good
suggestions?

The code is:

Option Explicit
Sub PaintCellsNotDependent()
'Written by Peder Wessel
Dim Rng As Range
Dim Cell As Range
Dim Container As Variant

'Selects the range to check
Set Rng = Application.InputBox("Select the range to be checked",
"Range", Type:=8)

'If there is no dependent there is an error
On Error Resume Next

'Set Container to nothing to make sure that if it becomes something
there is a dependent
Set Container = Nothing

For Each Cell In Rng
With Cell
Container = .DirectDependents
If Container Is Nothing Then .Interior.Color = RGB(95, 177,
39) 'Sets background color to green if NOT dependet'
Set Container = Nothing
End With
Next Cell

'Resets Error settings
On Error GoTo 0

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem with Nothing command

On Apr 10, 11:53*am, Wesslan wrote:
Hi I am struggling with a Nothing command.

If I have a cell that has a dependent, the background colour should
not be changed, whereas the colour should be changed if the cell lacks
dependents.

However, as it is now the macro changes the value irregardless. When
my container takes on a value (i.e is NOT nothing) it should not
proceed with the .interior command, but yet it does. Any good
suggestions?

The code is:

Option Explicit
Sub PaintCellsNotDependent()
'Written by Peder Wessel
Dim Rng As Range
Dim Cell As Range
Dim Container As Variant

'Selects the range to check
Set Rng = Application.InputBox("Select the range to be checked",
"Range", Type:=8)

'If there is no dependent there is an error
On Error Resume Next

'Set Container to nothing to make sure that if it becomes something
there is a dependent
Set Container = Nothing

For Each Cell In Rng
* * With Cell
* * * * Container = .DirectDependents
* * * * If Container Is Nothing Then .Interior.Color = RGB(95, 177,
39) * * * * 'Sets background color to green if NOT dependet'
* * * * Set Container = Nothing
* * End With
Next Cell

'Resets Error settings
On Error GoTo 0

End Sub


Never mind, I found the solution. I need to set a "set" command in
front of the container = .directdependents
so the code becomes:

Sub PaintCellsNotDependent()
'Written by Peder Wessel
Dim Rng As Range
Dim Cell As Range
Dim Container As Variant

'Selects the range to check
Set Rng = Application.InputBox("Select the range to be checked",
"Range", Type:=8)

'If there is no dependent there is an error
On Error Resume Next

'Set Container to nothing to make sure that if it becomes something
there is a dependent
Set Container = Nothing

For Each Cell In Rng
With Cell
Set Container = .DirectDependents
If Container Is Nothing Then .Interior.Color = RGB(95, 177,
39) 'Sets background color to green if NOT dependet'
Set Container = Nothing
End With
Next Cell

'Resets Error settings
On Error GoTo 0

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Problem with Nothing command

Yes - the DirectDependants proprty returns a range so to avoid confusion you:

Dim Container As Variant

should have been ~:

Dim Container As range

then it would have been easy to pick up error!
"Wesslan" wrote:

On Apr 10, 11:53 am, Wesslan wrote:
Hi I am struggling with a Nothing command.

If I have a cell that has a dependent, the background colour should
not be changed, whereas the colour should be changed if the cell lacks
dependents.

However, as it is now the macro changes the value irregardless. When
my container takes on a value (i.e is NOT nothing) it should not
proceed with the .interior command, but yet it does. Any good
suggestions?

The code is:

Option Explicit
Sub PaintCellsNotDependent()
'Written by Peder Wessel
Dim Rng As Range
Dim Cell As Range
Dim Container As Variant

'Selects the range to check
Set Rng = Application.InputBox("Select the range to be checked",
"Range", Type:=8)

'If there is no dependent there is an error
On Error Resume Next

'Set Container to nothing to make sure that if it becomes something
there is a dependent
Set Container = Nothing

For Each Cell In Rng
With Cell
Container = .DirectDependents
If Container Is Nothing Then .Interior.Color = RGB(95, 177,
39) 'Sets background color to green if NOT dependet'
Set Container = Nothing
End With
Next Cell

'Resets Error settings
On Error GoTo 0

End Sub


Never mind, I found the solution. I need to set a "set" command in
front of the container = .directdependents
so the code becomes:

Sub PaintCellsNotDependent()
'Written by Peder Wessel
Dim Rng As Range
Dim Cell As Range
Dim Container As Variant

'Selects the range to check
Set Rng = Application.InputBox("Select the range to be checked",
"Range", Type:=8)

'If there is no dependent there is an error
On Error Resume Next

'Set Container to nothing to make sure that if it becomes something
there is a dependent
Set Container = Nothing

For Each Cell In Rng
With Cell
Set Container = .DirectDependents
If Container Is Nothing Then .Interior.Color = RGB(95, 177,
39) 'Sets background color to green if NOT dependet'
Set Container = Nothing
End With
Next Cell

'Resets Error settings
On Error GoTo 0

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
Command Button Problem albertmb Excel Discussion (Misc queries) 6 June 22nd 08 01:06 PM
Subtotal command problem Martin B Excel Worksheet Functions 1 November 26th 06 01:34 PM
Problem with MID (any text) Command Scott Excel Worksheet Functions 2 May 2nd 06 09:45 PM
command bar problem helpwithXL Excel Programming 0 May 23rd 05 05:50 PM
command bar problem helpwithXL Excel Programming 2 May 18th 05 06:39 PM


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

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"