MD. ABDUL KADER is an engineer with a talent for Excel and a passion for VBA programming. To him, programming is like a time-saving wizard, making data manipulation, file handling, and internet interactions a breeze. His skill set extends to SWM, GIS, RS, and SPSS. He holds a B.Sc in Urban & Regional Planning from Chittagong University of Engineering and Technology and has shifted to become a content developer. In this role, he crafts technical content centred around Excel and VBA. Outside the professional realm, catch him immersed in books, exploring new places during travels, and watching movies.

## Designation

Team Leader at ExcelDemy in SOFTEKO.

## Education

B.Sc in Urban & Regional Planning, Chittagong University of Engineering and Technology

## Expertise

SWM, GIS, RS, SPSS, MS Excel, PowerQuery, PowerPivot & VBA

## Experience

• Technical Content Writing
• Team Management

## Summary

• Currently working as Team Leader of ExcelDemy.
• He started writing technical content for Excel & VBA for ExcelDemy in 2021.

## How to Extract Multiple Numbers from a String in Excel – 6 Methods

The dataset showcases  ID (7 digits), Name, and ZIP Code (5 digits) in a single cell. To extract ID and ZIP Code:   Method 1 - Using the ...

## How to Create Rows within a Cell in Excel (3 Methods)

Let’s introduce today’s dataset where the Names of some employees are provided along with their corresponding States and E-mails (inserted sequentially). Let's ...

## Ranking Based on Multiple Criteria in Excel (4 Cases)

The sample dataset contains student scores in Math and Psychology as well as each student's group. We'll rank the students according to the scores. ...

## How to Merge an Excel File into a Word Document – 2 Examples

Example 1 - Merge a Single Page in an Excel File into a Word Document The sample dataset showcases a sales report: Sales Rep, Product ID and Category, States, ...

## How to Insert a Column to the Left in Excel (6 Methods)

We'll use a simple dataset where the Number of Visits for each website is provided along with the Names and Categories of the Sites. We want to add a column to ...

## The Sort and Filter is Not Working in Excel

The sample dataset showcases Number of Visits of websites, their Name and Category. Dates and Platforms are also given. Solution 1 - There are Blank ...

## How to Print Excel Sheet with Table (4 Methods + Tricks)

Method 1 - Print Only Table from an Excel Sheet Our sample dataset is in the B4:I79 cell range. The worksheet has a chart, the table, and the title of ...

## How to Filter Based on Cell Value Using Excel VBA (4 Methods)

Let’s introduce today’s dataset (B4:E15 cell range) as shown in the following screenshot. Here, the Number of Visits for each website is provided along with ...

## Excel Wrap Text Cutting off Words: 4 Solutions

Fix 1 - If the Row Height Is Fixed If the row height is predefined, you get the problem of cutting off words after wrapping the text in Excel cell. We went ...

## How to Find Duplicates in Two Different Excel Workbooks (5 Methods)

Let’s assume we have two different datasets with a common field (Employee Name) in two different sheets in two workbooks. The first dataset is in Sheet1 of the ...

## The Excel Wrap Text Option is Not Working for Merged Cells – 5 Solutions

The dataset showcases Quotes and the corresponding Authors. Each quote covers 3 cells and the text isn't completely displayed. Wrap the text after merging ...

## How to Do Linear Interpolation in Excel (7 Handy Methods)

Let’s say, you know the values of two known points A (x1,y1) and C (x2,y2) of a straight line and you want to determine the unknown value y from the point of B ...

## How to Calculate the Running Total by Group Using the Excel Power Query – 2 Methods

The dataset showcases Items and Sales over three months. To calculate the running total by group (Month), choose a month:   Method 1 - Running ...

## How to Link Picture to Cell Value in Excel: 4 Methods

The example dataset below shows the yearly Sales of various Products. The entire dataset is located in the B4:D13 cell range. Method 1 - Using the ...

## How to Put Parentheses for Negative Numbers in Excel

The following sample dataset of Purchase Price and Selling Price are provided in USD for each Product. If you subtract the Selling Price from the Purchase ...

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

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.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.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,