Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
Viral
 
Posts: n/a
Default Locking cels using a UDF

I'm not entirely sure if this is possible or not... but here we go.

I'm looking to lock down two cells in a row after data is input into the
cells... for the entire spreadsheet... or at least 2000 rows. I think the
easiest way would be to have a function since I could fill down and the two
cells would change relative to the position of the function.

Basically, I'm looking to lock cells A1:B1 and so on all the way down the
spreadsheet. I've seen some subroutines to lock cells, but I don't know how
to use them in the spreadsheet, and I'm having a heck of a time trying to get
this to work.

I'd appreciate any help. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.newusers
Bob Phillips
 
Posts: n/a
Default Locking cels using a UDF

Can't do it with a function, but with event code

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G2:H2000"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Locked = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Viral" <u16718@uwe wrote in message news:58ec62eb8a08e@uwe...
I'm not entirely sure if this is possible or not... but here we go.

I'm looking to lock down two cells in a row after data is input into the
cells... for the entire spreadsheet... or at least 2000 rows. I think the
easiest way would be to have a function since I could fill down and the

two
cells would change relative to the position of the function.

Basically, I'm looking to lock cells A1:B1 and so on all the way down the
spreadsheet. I've seen some subroutines to lock cells, but I don't know

how
to use them in the spreadsheet, and I'm having a heck of a time trying to

get
this to work.

I'd appreciate any help. Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.newusers
Viral
 
Posts: n/a
Default Locking cels using a UDF

Awesome, Thanks a million man. Really needed to know how to use the
subroutines, thanks again.

Bob Phillips wrote:
Can't do it with a function, but with event code

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G2:H2000"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Locked = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

I'm not entirely sure if this is possible or not... but here we go.

[quoted text clipped - 9 lines]

I'd appreciate any help. Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.newusers
Gord Dibben
 
Posts: n/a
Default Locking cels using a UDF

Viral

Just a note here.

The cells will still be editable until you Protect the Worksheet.


Gord Dibben Excel MVP

On Fri, 16 Dec 2005 14:43:48 GMT, "Viral" <u16718@uwe wrote:

Awesome, Thanks a million man. Really needed to know how to use the
subroutines, thanks again.

Bob Phillips wrote:
Can't do it with a function, but with event code

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G2:H2000"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Locked = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

I'm not entirely sure if this is possible or not... but here we go.

[quoted text clipped - 9 lines]

I'd appreciate any help. Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.newusers
Viral via OfficeKB.com
 
Posts: n/a
Default Locking cels using a UDF

Yep, found that out. Played around with it a bit, but I got it to do what I
wanted finally... I decided I wanted to do the same thing for another set of
cells in two other columns... as well as protect the page so the cells
couldn't be altered after entering data, here's what I have working. Wooga!

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A2:B2000"
On Error GoTo ws_exit:
Application.EnableEvents = False
ActiveSheet.Unprotect Password:="1"
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Locked = True
End With
End If
ActiveSheet.Protect Password:="1"
ActiveSheet.EnableSelection = xlUnlockedCells

ws_exit:
Const WS_RANGER As String = "H2:I2000"
On Error GoTo ws_exit2:
Application.EnableEvents = False
ActiveSheet.Unprotect Password:="1"
If Not Intersect(Target, Me.Range(WS_RANGER)) Is Nothing Then
With Target
.Locked = True
End With
End If
ActiveSheet.Protect Password:="1"
ActiveSheet.EnableSelection = xlUnlockedCells

ws_exit2:
Application.EnableEvents = True
End Sub

Only thing further is to have only the unlocked cells able to be selected
when the program opens... since they seem to be reverting back to editable
once the file is re-opened.

Thanks a bunch!!

Gord Dibben wrote:
Viral

Just a note here.

The cells will still be editable until you Protect the Worksheet.

Gord Dibben Excel MVP

Awesome, Thanks a million man. Really needed to know how to use the
subroutines, thanks again.

[quoted text clipped - 28 lines]

I'd appreciate any help. Thanks.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...l-new/200512/1


  #6   Report Post  
Posted to microsoft.public.excel.newusers
Gord Dibben
 
Posts: n/a
Default Locking cels using a UDF

Haven't tested your code, but looks impressive and you say it does the job.

Goodonya.


Gord

On Fri, 16 Dec 2005 21:39:50 GMT, "Viral via OfficeKB.com" <u16718@uwe wrote:

Yep, found that out. Played around with it a bit, but I got it to do what I
wanted finally... I decided I wanted to do the same thing for another set of
cells in two other columns... as well as protect the page so the cells
couldn't be altered after entering data, here's what I have working. Wooga!

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A2:B2000"
On Error GoTo ws_exit:
Application.EnableEvents = False
ActiveSheet.Unprotect Password:="1"
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Locked = True
End With
End If
ActiveSheet.Protect Password:="1"
ActiveSheet.EnableSelection = xlUnlockedCells

ws_exit:
Const WS_RANGER As String = "H2:I2000"
On Error GoTo ws_exit2:
Application.EnableEvents = False
ActiveSheet.Unprotect Password:="1"
If Not Intersect(Target, Me.Range(WS_RANGER)) Is Nothing Then
With Target
.Locked = True
End With
End If
ActiveSheet.Protect Password:="1"
ActiveSheet.EnableSelection = xlUnlockedCells

ws_exit2:
Application.EnableEvents = True
End Sub

Only thing further is to have only the unlocked cells able to be selected
when the program opens... since they seem to be reverting back to editable
once the file is re-opened.

Thanks a bunch!!

Gord Dibben wrote:
Viral

Just a note here.

The cells will still be editable until you Protect the Worksheet.

Gord Dibben Excel MVP

Awesome, Thanks a million man. Really needed to know how to use the
subroutines, thanks again.

[quoted text clipped - 28 lines]

I'd appreciate any help. Thanks.

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
Locking Text beng120 Excel Discussion (Misc queries) 1 November 5th 05 06:27 PM
selecting cell groups and locking up Bugged by Excel? Excel Discussion (Misc queries) 3 August 4th 05 01:07 PM
locking workbooks Nick Excel Discussion (Misc queries) 0 July 6th 05 02:32 PM
How do I count number of cels the matches 2 conditions ? Abra Excel Worksheet Functions 2 February 27th 05 08:56 PM
Locking certain cells Marvin Excel Worksheet Functions 1 December 7th 04 07:13 PM


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