I am trying to create a Macro that will allow me to Freeze an entire line in Sheet 1 (Tbl_Data) IF column A's "Trend ID" Number Matches the Trend ID that is found in Sheet 2 (Tbl_Review).
-The Tbl_Review Page must always stay locked (This workbook has a form that a user fills out)
-The Tbl_Data Page has Trend ID's in column A that are not found in Tbl_Review highlighted as yellow.
Below is code for a similar macro to allow editing only to highlighted rows in a single worksheet only. I was hoping to touch this up. Could anyone help me out as I am fairly new to code! Thank you!
Sub Lock_WB_2()
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="1234"
Selection.Locked = False
Selection.FormulaHidden = False
Selection.Interior.ColorIndex = xlColorIndexNone
'Add Autofilter to row 1
Rows(4).Select
If ActiveSheet.AutoFilterMode = False Then
Selection.AutoFilter
'Selection.Locked = True
End If
'Freez panes are added to rows and columns before the cell B4
Range("B5").Select
ActiveWindow.FreezePanes = True
'Find Wrokheet and review date columns by name and store column numbers in variables
colindex_worksheet = 0
colindex_date = 0
i = 1
Range("A1").Select
Do While Cells(4, i) <> "" ' Or Cells(3, i + 1) <> "" Or Cells(3, i + 2) <> ""
If Cells(4, i) = "Worksheet" Then
colindex_worksheet = i
End If
If Cells(4, i) = "Review Date" Then
colindex_date = i
Exit Do
End If
i = i + 1
Loop
Range(Cells(4, 1), Cells(4, colindex_date)).Select
Selection.Locked = True
'If colindex_worksheet = 0 Or colindex_date = 0 Then
'MsgBox ("Worksheet column or Review Date Column missing")
'GoTo 0
'End If
'flag = 0
'Range("A:A").Select
'Selection.Locked = True
'Selection.FormulaHidden = False
'Start at row 3 and lock the row if there is an entry in "Review Date column" else highlight the row Yellow.
'Also merged cells in review date column are incorporated to be locked
i = 5
Do While Cells(i, colindex_worksheet) <> "" Or Cells(i, colindex_worksheet).MergeCells = True
If IsEmpty(Cells(i, colindex_date)) Then
'Cells(i, colindex_date).Select
'Selection.EntireRow.Select
Range(Cells(i, 1), Cells(i, colindex_date)).Select
Selection.Locked = False
Selection.Interior.ColorIndex = 40
Else
'(Cells(i, colindex_date)) <> "" then
Cells(i, colindex_date).Select
Range(Cells(i, 1), Cells(i, colindex_date)).Select
'Selection.EntireRow.Select
Selection.Interior.ColorIndex = 0
Selection.Locked = True
Selection.FormulaHidden = False
'if cells are merged, count number of rows that are merged and add it to i to jump to the row after merged cell
If i > 1 Then
If Cells(i, colindex_date).MergeCells Then
Cells(i, colindex_date).Activate
k = ActiveCell.MergeArea.Rows.Count
Range(Cells(i, 1), Cells(i, colindex_date)).Select
'Selection.EntireRow.Select
Selection.Interior.ColorIndex = 0
i = i + k - 1
End If
End If
End If
i = i + 1
Loop
'Allow used to filter data, insert columns and rows
'Range(Cells(1, 1), Cells(1, colindex_date)).Select
ActiveSheet.Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True _
'AllowInsertingRows:=True, AllowInsertingColumns:=True _
With ActiveSheet
.EnableSelection = xlNoRestrictions
End With
Application.ScreenUpdating = True
ActiveWorkbook.Save
End Sub
-The Tbl_Review Page must always stay locked (This workbook has a form that a user fills out)
-The Tbl_Data Page has Trend ID's in column A that are not found in Tbl_Review highlighted as yellow.
Below is code for a similar macro to allow editing only to highlighted rows in a single worksheet only. I was hoping to touch this up. Could anyone help me out as I am fairly new to code! Thank you!
Sub Lock_WB_2()
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="1234"
Selection.Locked = False
Selection.FormulaHidden = False
Selection.Interior.ColorIndex = xlColorIndexNone
'Add Autofilter to row 1
Rows(4).Select
If ActiveSheet.AutoFilterMode = False Then
Selection.AutoFilter
'Selection.Locked = True
End If
'Freez panes are added to rows and columns before the cell B4
Range("B5").Select
ActiveWindow.FreezePanes = True
'Find Wrokheet and review date columns by name and store column numbers in variables
colindex_worksheet = 0
colindex_date = 0
i = 1
Range("A1").Select
Do While Cells(4, i) <> "" ' Or Cells(3, i + 1) <> "" Or Cells(3, i + 2) <> ""
If Cells(4, i) = "Worksheet" Then
colindex_worksheet = i
End If
If Cells(4, i) = "Review Date" Then
colindex_date = i
Exit Do
End If
i = i + 1
Loop
Range(Cells(4, 1), Cells(4, colindex_date)).Select
Selection.Locked = True
'If colindex_worksheet = 0 Or colindex_date = 0 Then
'MsgBox ("Worksheet column or Review Date Column missing")
'GoTo 0
'End If
'flag = 0
'Range("A:A").Select
'Selection.Locked = True
'Selection.FormulaHidden = False
'Start at row 3 and lock the row if there is an entry in "Review Date column" else highlight the row Yellow.
'Also merged cells in review date column are incorporated to be locked
i = 5
Do While Cells(i, colindex_worksheet) <> "" Or Cells(i, colindex_worksheet).MergeCells = True
If IsEmpty(Cells(i, colindex_date)) Then
'Cells(i, colindex_date).Select
'Selection.EntireRow.Select
Range(Cells(i, 1), Cells(i, colindex_date)).Select
Selection.Locked = False
Selection.Interior.ColorIndex = 40
Else
'(Cells(i, colindex_date)) <> "" then
Cells(i, colindex_date).Select
Range(Cells(i, 1), Cells(i, colindex_date)).Select
'Selection.EntireRow.Select
Selection.Interior.ColorIndex = 0
Selection.Locked = True
Selection.FormulaHidden = False
'if cells are merged, count number of rows that are merged and add it to i to jump to the row after merged cell
If i > 1 Then
If Cells(i, colindex_date).MergeCells Then
Cells(i, colindex_date).Activate
k = ActiveCell.MergeArea.Rows.Count
Range(Cells(i, 1), Cells(i, colindex_date)).Select
'Selection.EntireRow.Select
Selection.Interior.ColorIndex = 0
i = i + k - 1
End If
End If
End If
i = i + 1
Loop
'Allow used to filter data, insert columns and rows
'Range(Cells(1, 1), Cells(1, colindex_date)).Select
ActiveSheet.Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True _
'AllowInsertingRows:=True, AllowInsertingColumns:=True _
With ActiveSheet
.EnableSelection = xlNoRestrictions
End With
Application.ScreenUpdating = True
ActiveWorkbook.Save
End Sub