Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code Erasing Cell Contents Inappropriately

I have the following code, which works correctly to hide/unhide rows as the
user inputs responses and also to erase data appropriately. However, when I
run another macro to check for certain things on the worksheet, somehow what
is in Cell C91:M91 gets erased even though it is not suppose to if C90:F90 =
"via a method not listed". It also hides row 91 even though 91 is suppose to
stay visible if if C90:F90 = "via a method not listed". There is nothing in
this other code that references anything in rows 90 or 91. After working all
day to try and figure out what I've done wrong, am asking for some help. I
feel sure it is in the way I've written the following code........thanks for
any assistance that can be provided.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("$C$89")) Is Nothing) Then
If Target.Value = "Yes" Then
ActiveSheet.Unprotect Password:="alaska"
Range("90:90,92:92").EntireRow.Hidden = False
Rows("91").Hidden = True
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("90:92").Hidden = True
Range("C90:F90,C92:D92,C91:M91").ClearContents
End If
End If
If Not Intersect(Target, Range("C90:F90")) Is Nothing Then
If Target(1).Value = "via a method not listed" Then
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = False
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = True
Range("C91:M91").ClearContents
End If
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code Erasing Cell Contents Inappropriately

If you code chagnes C89 and C89 < Yes, then you clear C90:F90 which will
fire the change macro again and do what you describe.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("$C$89")) Is Nothing) Then
If Target.Value = "Yes" Then
ActiveSheet.Unprotect Password:="alaska"
Range("90:90,92:92").EntireRow.Hidden = False
Rows("91").Hidden = True
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("90:92").Hidden = True
Application.EnableEvents = False
Range("C90:F90,C92:D92,C91:M91").ClearContents
Application.EnableEvents = True
End If
End If
If Not Intersect(Target, Range("C90:F90")) Is Nothing Then
If Target(1).Value = "via a method not listed" Then
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = False
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = True
Application.EnableEvents = False
Range("C91:M91").ClearContents
Application.EnableEvents = True
End If
End If
End Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
I have the following code, which works correctly to hide/unhide rows as

the
user inputs responses and also to erase data appropriately. However, when

I
run another macro to check for certain things on the worksheet, somehow

what
is in Cell C91:M91 gets erased even though it is not suppose to if C90:F90

=
"via a method not listed". It also hides row 91 even though 91 is suppose

to
stay visible if if C90:F90 = "via a method not listed". There is nothing

in
this other code that references anything in rows 90 or 91. After working

all
day to try and figure out what I've done wrong, am asking for some help.

I
feel sure it is in the way I've written the following code........thanks

for
any assistance that can be provided.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("$C$89")) Is Nothing) Then
If Target.Value = "Yes" Then
ActiveSheet.Unprotect Password:="alaska"
Range("90:90,92:92").EntireRow.Hidden = False
Rows("91").Hidden = True
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("90:92").Hidden = True
Range("C90:F90,C92:D92,C91:M91").ClearContents
End If
End If
If Not Intersect(Target, Range("C90:F90")) Is Nothing Then
If Target(1).Value = "via a method not listed" Then
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = False
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = True
Range("C91:M91").ClearContents
End If
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code Erasing Cell Contents Inappropriately

Thanks, Tom; your expertise is a life saver!

"Tom Ogilvy" wrote:

If you code chagnes C89 and C89 < Yes, then you clear C90:F90 which will
fire the change macro again and do what you describe.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("$C$89")) Is Nothing) Then
If Target.Value = "Yes" Then
ActiveSheet.Unprotect Password:="alaska"
Range("90:90,92:92").EntireRow.Hidden = False
Rows("91").Hidden = True
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("90:92").Hidden = True
Application.EnableEvents = False
Range("C90:F90,C92:D92,C91:M91").ClearContents
Application.EnableEvents = True
End If
End If
If Not Intersect(Target, Range("C90:F90")) Is Nothing Then
If Target(1).Value = "via a method not listed" Then
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = False
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = True
Application.EnableEvents = False
Range("C91:M91").ClearContents
Application.EnableEvents = True
End If
End If
End Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
I have the following code, which works correctly to hide/unhide rows as

the
user inputs responses and also to erase data appropriately. However, when

I
run another macro to check for certain things on the worksheet, somehow

what
is in Cell C91:M91 gets erased even though it is not suppose to if C90:F90

=
"via a method not listed". It also hides row 91 even though 91 is suppose

to
stay visible if if C90:F90 = "via a method not listed". There is nothing

in
this other code that references anything in rows 90 or 91. After working

all
day to try and figure out what I've done wrong, am asking for some help.

I
feel sure it is in the way I've written the following code........thanks

for
any assistance that can be provided.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("$C$89")) Is Nothing) Then
If Target.Value = "Yes" Then
ActiveSheet.Unprotect Password:="alaska"
Range("90:90,92:92").EntireRow.Hidden = False
Rows("91").Hidden = True
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("90:92").Hidden = True
Range("C90:F90,C92:D92,C91:M91").ClearContents
End If
End If
If Not Intersect(Target, Range("C90:F90")) Is Nothing Then
If Target(1).Value = "via a method not listed" Then
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = False
Else
ActiveSheet.Unprotect Password:="alaska"
Rows("91").Hidden = True
Range("C91:M91").ClearContents
End If
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
Erasing contents and leaving the formula Octavio[_2_] New Users to Excel 6 August 8th 07 11:52 PM
VBA Code to identify contents of a cell SLS Excel Programming 3 September 22nd 04 11:13 PM
Run code based on cell contents Pete JM[_9_] Excel Programming 2 June 22nd 04 07:09 PM
How to validate in code the contents of a cell? Heather M. Excel Programming 1 November 11th 03 08:14 AM
run code after cell contents change Brian Excel Programming 0 September 5th 03 08:37 PM


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