Main Module
My code is working fine, the idea is to lock the entire row in the target workbook if source workbook cells in column b have a yellow color....
The question is how to replace the for-each loop with arrays for performance-wise, that's all?
Sub LockYellow()
With ThisWorkbook.Worksheets("Data")
.Unprotect "007"
.UsedRange.Locked = False
.Range("a1:z1").Locked = True
End With
' ---## Global
Dim SourceBook As Workbook
Set SourceBook = GetWorkbook(Source)
Dim X, xrange As Range
Set xrange = SourceBook.Worksheets("Data").Range("b2:b1499")
For Each X In xrange
'If X.Interior.Color = 65535 Then
If X.value = "User_1" Then
Dim u As String
u = X.Address
'ThisWorkbook.Worksheets("Data").Range(u).Value2 = SourceBook.Worksheets("Data").Range(u).Value2
'ThisWorkbook.Worksheets("Data").Range(u).Interior.Color = 65535
ThisWorkbook.Worksheets("Data").Range(u).EntireRow.Locked = True
End If
Next X
If Not SourceBook Is Nothing Then
SourceBook.Close savechanges:=False
End If
ThisWorkbook.Worksheets("Data").Protect "007"
End Sub
Helper Module
Public Const Source As String = "C:\Users\vv\Desktop\Sourcesheet.xlsx"
Public Function GetWorkbook(ByVal sFullName As String) As Workbook
Dim sFile As String
Dim wbReturn As Workbook
sFile = Dir(sFullName)
On Error Resume Next
Set wbReturn = Workbooks(sFile)
If wbReturn Is Nothing Then
Set wbReturn = Workbooks.Open(sFullName)
End If
On Error GoTo 0
Set GetWorkbook = wbReturn
End Function
Unionbut I haven't tested it.