+ Reply to Thread
Results 1 to 2 of 2

Automaticaly lock cell based on content of another cell

  1. #1
    Registered User
    Join Date
    12-14-2016
    Location
    Paris, France
    MS-Off Ver
    2010
    Posts
    3

    Automaticaly lock cell based on content of another cell

    Hello,

    I would like to know if there is a way to lock a cell based on the content of another cell on the same ligne ? (this action will occur multiple times in the sheet)

    So far I have this but it doesn't seem to work and looks quite heavy ...

    I would be very grateful if somebody could help me out on this :

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(ActiveSheet.Cells(32, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(32, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(32, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(32, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(33, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(32, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(33, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(33, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(34, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(32, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(34, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(34, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(35, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(35, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(35, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(35, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(36, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(32, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(36, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(36, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(37, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(37, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(37, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(37, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(38, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(38, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(38, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(38, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(39, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(39, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(39, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(39, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(40, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(40, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(40, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(40, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(41, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(41, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(41, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(41, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(42, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(42, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(42, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(42, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(43, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(43, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(43, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(43, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(44, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(44, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(44, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(44, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(45, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(45, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(45, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(45, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(46, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(46, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(46, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(46, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(47, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(47, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(47, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(47, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(48, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(48, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(48, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(48, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(49, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(49, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(49, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(49, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(50, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(50, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(50, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(50, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(51, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(51, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(51, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(51, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(52, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(52, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(52, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(52, 10)).Locked = False
    End If
    If Intersect(ActiveSheet.Cells(53, 9), Target) Is Not Nothing Then
    If ActiveSheet.Cells(53, 9).Text = "k€" Then
    ActiveSheet.Range(Cells(53, 10)).Locked = True
    Else
    ActiveSheet.Range(Cells(53, 10)).Locked = False
    End If
    End If
    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello Hippolyte,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to lock a cell content
    By Shadmani in forum Excel General
    Replies: 1
    Last Post: 11-14-2014, 01:13 AM
  2. Lock/unlock specific cells in a row based on another cell content of the same row
    By st_rod000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 02:58 AM
  3. copying cell content into a specific workbook based on the content in that cell
    By krishna reddy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2012, 03:52 AM
  4. Lock Cell Date Format NOT Content
    By mlmaclean in forum Excel General
    Replies: 4
    Last Post: 12-30-2010, 08:00 AM
  5. Automaticaly color a cell based on the value of another cell
    By Hatricke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2010, 08:55 PM
  6. Lock and clear cell content based on another cell's value
    By mohitmahajanin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2008, 06:30 AM
  7. Replies: 3
    Last Post: 10-23-2006, 08:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1