Lock range of Cells in row based on adjacent cell value

Excelkids

New Member
Joined
Oct 15, 2014
Messages
4
I am using vba code to review and Approve certain row of data using two set of sheets: 1st is "View_Form" where we review the entered data in specific form view. 2nd is "Tracker" where all the data is stored from external download.
In "View_Form" sheet we select File ID and all the data relevant to it get displayed and if all looks good we Click macro button "Approved" and the text "Approved" gets in the Column MY adjacent to the selected file ID else it would be blank.
It runs only once and then shows error as File ID not found. I want to restrict. That is if the MY cell contains text "Approved" that particular row from A:MY should get locked or should restrict the user from editing.
Should enable user to edit after using password to unprotect sheet say for example password as 1234.
Can any one help me out with this...
Current code for approval and lock:


<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Sub Approval()

Dim found As Range 'define variables
Dim SelectedFileID As String
Dim Lastrow As Long
Dim i As Long

SelectedFileID
= Sheets("View_Form").Range("SelFileID").Value 'get the currently selected File ID
Application
.DisplayAlerts = False
Set found = Sheets("Tracker").Range("B:B").Find(What:=SelectedFileID) 'find the file ID in the Sheet Tracker
If Not found Is Nothing Then 'if found
Sheets
("Tracker").Unprotect Password:="1234" 'change the password to whatever you wish, this unlocks the sheet
Sheets
("Tracker").Cells(found.Row, 363).Value = "Approved" 'change the value of the row it was found, but column 226 which is column HR
Sheets
("Tracker").Range("A1:MY1000").Cells.Locked = False 'keeps range unlocked
Lastrow
= Sheets("Tracker").Cells(Sheets("Tracker").Rows.Count, "A").End(xlUp).Row
For i = 3 To Lastrow
If Sheets("Tracker").Cells(i, 363).Value = "Approved" Then
Sheets
("Tracker").Rows(i).Cells.Locked = True
End If
Next i
Sheets
("Tracker").Protect Password:="1234" 'protect the sheet after updating to Approved on Column HR
Else
MsgBox
"ID not found in Sheet Tracker!", vbInformation 'if not found then show message
End If
ActiveWorkbook
.Save '---------------Save workbook
Application
.DisplayAlerts = True
End Sub</code>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top