Compare two similar sets of data in column A locking duplicate data and allowing editing of non-duplicate data

Ribs11380

New Member
Joined
Oct 5, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Here is a basic example of the two sheets I have to work with:
1664994795002.png
1664994819934.png
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

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