# Md. Abdul Kader

Hi! I am Abdul Kader and presently working as â€˜Excel & VBA Content Developerâ€™ at Exceldemy. I publish my articles related to Microsoft Excel here. In 2019, I completed my graduation in Urban and Regional Planning from Chittagong University of Engineering and Technology. Having extreme eagerness to learn, I want to develop my skills and capabilities higher.

## How to Calculate Running Total by Group Using Excel Power Query

Running totals simply means the cumulative sum of a sequence of values. The application of calculating running total is quite significant for business purposes ...

## How to Link Picture to Cell Value in Excel (4 Quick Methods)

When you have a larger dataset and you want to export an image from the particular cell values, a linked picture might be the best option. As the linked ...

## How to Put Parentheses for Negative Numbers in Excel

Placing parentheses for negative numbers is a common exercise popularly used by accountants to increase readability. Nowadays, it is also displayed in red ...

## Excel VBA: UserForm Image from Worksheet (3 Cases)

While creating or modifying a UserForm, you may need to add or create images from the worksheet. In this instructive session, Iâ€™ll demonstrate 3 methods to add ...

## How to Find and Replace within Selection in Excel (7 Methods)

Frequently, you may need to find a particular data, formatting, or even cell references and then replace it with something new. Find and Replace is one of the ...

## How to Use Dynamic Range for Last Row with VBA in Excel (3 Methods)

The VBA Dynamic Range provides you the opportunity to use the same code for newly added or removed data while working with a larger dataset. However, it will ...

## VLOOKUP Date Range and Return Value in Excel (4 Suitable Methods)

Often you may need to VLOOKUP dealing with the date. If you want to return a certain value or values for the date range instead of VLOOKUP by date, youâ€™re here ...

## How to Change Date Format in Pivot Table in Excel

Pivot Table, one of the powerful features in Excel, analyzes the larger dataset efficiently. But probably you have faced the problem of date formatting in the ...

## How to Count Unique Values in Filtered Column in Excel (5 Methods)

If you have a larger dataset and you need to apply filters in columns. More importantly, you might require to count only unique values except for the duplicate ...

## How to Convert Number to Text without Scientific Notation in Excel

Once you input any data for example a number, it will be stored typically as a number. More importantly, if the number of digits is greater than 15, your input ...

## How to Combine Cells into One with Line Break in Excel (5 Methods)

Sometimes we need to combine multiple cells into one keeping with the line break. Undoubtedly, Excel provides some quickest features to do that. In this ...

## How to Add a Checkbox in Excel (2 Steps + 4 Uses)

Most likely you see a checkbox that is mainly used for selecting or deselecting any option. Though the process of adding a checkbox in Excel is quite easy, you ...

## How to Lock Multiple Cells in Excel (6 Suitable Methods)

Basically, you may need to lock multiple cells for two reasons. One is to lock cells for protecting them from further edits or changes whereas the other reason ...

## How to Use FormulaR1C1 Absolute Reference in Excel VBA

While working in Excel, you might hear the absolute cell reference. This type of cell reference remains unchanged if you copy, move or even use it in an array. ...

## How to Apply Conditional Formatting in Excel If Another Cell Is Blank

Perhaps you may have a larger dataset with numerous blank cells. Using a popular highlighting tool i.e. Conditional Formatting, you are easily able to ...

Browsing All Comments By: Md. Abdul Kader
1. Hello EAC,
Thanks for your question. Most likely, you need to put a not equal sign (<>) inside the Ifâ€¦Then statement of your second code. So, the corrected second code will be as follows-

``````Sub block()
Dim hz As String
Dim hz1 As String

hz1 = InputBox("repeat password")

If hz <> hz1 Then
MsgBox "The repeated password is not identical!", vbExclamation
hz = ""
hz1 = ""
Else
Columns("D:F").Select
Selection.Locked = False
Range("D8:F12").Select
Selection.Locked = True
Range("a1").Select
ActiveSheet.Protect hz
End If
End Sub``````

However, your used three codes are quite messy. I would like to suggest that you can use the following code to lock a specific cell range in all worksheets of your Excel file.

``````Sub Lock_CellRange_AllSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect Password:="1234" 'Replace the password if you want
ws.Range("D8:F12").Locked = True 'Replace the cell range
ws.Protect Password:="1234", UserInterfaceOnly:=True 'Replace the password with the actual password for the workbook if it is protected
Next ws
End Sub``````

Again, try this code to unlock the specific cell range in all worksheets.

``````Sub Unlock_CellRange_AllSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect Password:="1234" 'Replace the password if you want
ws.Range("D8:F12").Locked = False 'Replace the cell range
ws.Protect Password:="1234", UserInterfaceOnly:=True 'Replace the password with the actual password for the workbook if it is protected
Next ws
End Sub``````

I hope these will work! Moreover, you can follow lock and unlock cells using VBA to explore more efficient methods.

2. Hello Michael,
Please specify your problem in detail or send the excel file via [email protected] email address.

3. Dear Deka,
It’s nice to hear from you with such wonderful appreciation. I myself always try to represent Excel applications in a more user-friendly way. And we, the ExcelDemy team, are working as a one-stop Excel solution provider.
Thanks, and take care of yourself. Goodbye!