Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default worksheet change

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default worksheet change

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default worksheet change

Hi Jim

I have a syntax error in the following line of code

if target.value < '' then .Undo

I tried using double quotes and single quotes, neither corrected the error.

Do you have any suggestion on how I can correct this error?

Thanks for any help

"Jim Thomlinson" wrote:

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default worksheet change

This didn't work:

if target.value < "" then .Undo



ram wrote:

Hi Jim

I have a syntax error in the following line of code

if target.value < '' then .Undo

I tried using double quotes and single quotes, neither corrected the error.

Do you have any suggestion on how I can correct this error?

Thanks for any help

"Jim Thomlinson" wrote:

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default worksheet change

Hi Dave,

When I use "" I still can't enter data in a cell that is blank, it will
undo the entry and the cell will remain blank

Thanks for any help

"Dave Peterson" wrote:

This didn't work:

if target.value < "" then .Undo



ram wrote:

Hi Jim

I have a syntax error in the following line of code

if target.value < '' then .Undo

I tried using double quotes and single quotes, neither corrected the error.

Do you have any suggestion on how I can correct this error?

Thanks for any help

"Jim Thomlinson" wrote:

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default worksheet change

Maybe...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "" Then Exit Sub
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

This allows you to clear a cell.

Remember target.value is what's there after the change--not before.



ram wrote:

Hi Dave,

When I use "" I still can't enter data in a cell that is blank, it will
undo the entry and the cell will remain blank

Thanks for any help

"Dave Peterson" wrote:

This didn't work:

if target.value < "" then .Undo



ram wrote:

Hi Jim

I have a syntax error in the following line of code

if target.value < '' then .Undo

I tried using double quotes and single quotes, neither corrected the error.

Do you have any suggestion on how I can correct this error?

Thanks for any help

"Jim Thomlinson" wrote:

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default worksheet change

The following code answered my question, Thanks to all

Dim Oldvalue As Variant


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Oldvalue = Target(1).Formula

End Sub



Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Column = 1 And Oldvalue < "" Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
End With
End If
End Sub

"ram" wrote:

Hi Dave,

When I use "" I still can't enter data in a cell that is blank, it will
undo the entry and the cell will remain blank

Thanks for any help

"Dave Peterson" wrote:

This didn't work:

if target.value < "" then .Undo



ram wrote:

Hi Jim

I have a syntax error in the following line of code

if target.value < '' then .Undo

I tried using double quotes and single quotes, neither corrected the error.

Do you have any suggestion on how I can correct this error?

Thanks for any help

"Jim Thomlinson" wrote:

Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
with Application
.EnableEvents = False
if target.value < '' then .Undo
.EnableEvents = True
.Speech.Speak "Locked Cell"
end with
End If
End Sub

One thing to keep in mind is that this code will not execute if the user
pastes into this column...
--
HTH...

Jim Thomlinson


"ram" wrote:

I have the following code to protect cells in a shared workbook. What I'm
trying to do is tun off the undo if the cell is blank

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Application.Speech.Speak "Locked Cell"
End If
End Sub

Thanks for any help.

Thanks for all the help today


--

Dave Peterson

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
how to change the pivot chart automaticaly as values in the worksheet change Vinay Vasu Excel Worksheet Functions 0 May 3rd 10 04:25 PM
change formula in a shared worksheet without losing change history DCE Excel Worksheet Functions 5 July 25th 08 01:37 PM
Change to Worksheet Change Event Steph[_6_] Excel Programming 2 October 19th 05 03:42 PM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM


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