Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Macro Test for Value

I am trying to test for "R" in any cell that was changed, if so it remains
unlocked all others should be locked. I have tried all sorts of items and
always get a Error 13 type mismatch. What am I doing worng? Please Help

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "36"
Dim rArea As Range
Dim rCell As Range

Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
If Target.Value = Not "R" Then
.Locked = Not IsEmpty(.Value)
Else
End If
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Macro Test for Value

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "36"
Dim rArea As Range
Dim rCell As Range

Me.Unprotect Password:=sPWORD
For Each rArea In Target
With rArea
If not .Value = "R" Then
.Locked = Not IsEmpty(.Value)
End If
End With
Next rArea
Me.Protect Password:=sPWORD
End Sub

"PhilosophersSage" wrote:

I am trying to test for "R" in any cell that was changed, if so it remains
unlocked all others should be locked. I have tried all sorts of items and
always get a Error 13 type mismatch. What am I doing worng? Please Help

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "36"
Dim rArea As Range
Dim rCell As Range

Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
If Target.Value = Not "R" Then
.Locked = Not IsEmpty(.Value)
Else
End If
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Macro Test for Value

Thank you! Still new to VBA thanks for helping me get things right!

"Luke M" wrote:

'This line is incorrect:
If Target.Value = Not "R" Then

'Change to:
If Not (Target.Value = "R") Then

Do note that nowhere in your macro does it have the ability to unlock the
cell incase it has changed back to R. Is this a problem?
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"PhilosophersSage" wrote:

I am trying to test for "R" in any cell that was changed, if so it remains
unlocked all others should be locked. I have tried all sorts of items and
always get a Error 13 type mismatch. What am I doing worng? Please Help

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "36"
Dim rArea As Range
Dim rCell As Range

Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
If Target.Value = Not "R" Then
.Locked = Not IsEmpty(.Value)
Else
End If
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,722
Default Macro Test for Value

'This line is incorrect:
If Target.Value = Not "R" Then

'Change to:
If Not (Target.Value = "R") Then

Do note that nowhere in your macro does it have the ability to unlock the
cell incase it has changed back to R. Is this a problem?
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"PhilosophersSage" wrote:

I am trying to test for "R" in any cell that was changed, if so it remains
unlocked all others should be locked. I have tried all sorts of items and
always get a Error 13 type mismatch. What am I doing worng? Please Help

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "36"
Dim rArea As Range
Dim rCell As Range

Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
If Target.Value = Not "R" Then
.Locked = Not IsEmpty(.Value)
Else
End If
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
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
looping macro to test for borders SteveDB1 Excel Programming 9 January 29th 09 07:03 PM
Test if macro is called by another macro DaveM[_2_] Excel Programming 3 June 24th 08 06:23 PM
exit macro after test of cell value Pepestru Excel Programming 4 February 23rd 07 02:36 PM
How to test cell contents in a macro? JennyGard Excel Programming 4 February 22nd 06 03:08 PM
How can I test if a Macro if firing? ZZBC Excel Worksheet Functions 6 January 31st 06 03:09 AM


All times are GMT +1. The time now is 06:39 PM.

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"