How to lock specific cells using VBA after dropdown selection.

subhan1029

New Member
Joined
Mar 29, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
After Dropdown selection in C8,
I want to Lock specific cells from D8:J8
Can Anyone pls help me to write a VGA Code........
Thank you in advance......
 

Attachments

  • Untitled.png
    Untitled.png
    173.2 KB · Views: 7

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Which specific cells in D8:J8 do you want to lock and what is the criteria for each cell?
 
Upvote 0
If C8="Rectangular" then (D1,E1,i1,J1) should be lock
if C8="Circular" then (D1 to G1) should be lock
if C8= "ISA" or "ISMC" or "ISMB" then(E1,G8 to J8) Should lock
if C8="Fastener" then (E8 to J8) should lock
if c8="Flange" then (F8 to J8) Should be lock
if C8="Pipes" then(G8 to J8) Should be lock

*please provide the codes so that it automatically go's on next row.

Thank you so much for your reply
Hope you will help.
 
Upvote 0
Start by unlocking all the cells in your sheet. The macro will protect the sheet with a password. This is necessary in order to lock the cells. Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Change the password (in red) to suit your needs. Close the code window to return to your sheet. Make a selection in column C.
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 3 Then Exit Sub
    ActiveSheet.Unprotect Password:="xxxx"
    ActiveSheet.Cells.Locked = False
    Select Case Target.Value
        Case "Rectangular"
            Range("D1,E1,I1,J1").Locked = True
        Case "Circular"
            Range("D1:G1").Locked = True
        Case "ISA", "ISMC", "ISMB"
            Range("E1").Locked = True
            Range("G" & Target.Row).Resize(, 4).Locked = True
        Case "Fastener"
            Range("E" & Target.Row).Resize(, 6).Locked = True
        Case "Flange"
            Range("F" & Target.Row).Resize(, 5).Locked = True
        Case "Pipes"
            Range("G" & Target.Row).Resize(, 4).Locked = True
    End Select
    ActiveSheet.Protect Password:="xxxx"
    ActiveSheet.EnableSelection = xlUnlockedCells
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
Hi....
Above code is not working for me
please find attached image for reference
kindly suggest what to do








Master BOQ - Copy - Copy.xlsx
ABCDEFGHIJKLNO
1
2
3 ESTIMATION SHEET
4
5
6
7Sr. No.DescriptionC/SSizeSch / TypeL (mm)W (mm)Thk/Ht (mm)OD (mm)ID (mm)MOC (mm)Qty (Nos)Weight (Kg) Amount
81ExampleRectangular12341234123412341234 
92ExampleCircular12341234123412341234 
103ExampleISA65 x 65 x 8123412341234123412340.00
114ExamplePipes_80NB20123412341234123412340.00
125ExampleFastner12341234123412341234 
136ExampleCircular12341234123412341234 
147ExampleFastnerM12 x 65123412341234####12340.00
158ExampleFlange_.40NBWNRF0.00
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A8:O17Cellcontains a blank value textNO
 

Attachments

  • Untitled.png
    Untitled.png
    83.1 KB · Views: 2
Upvote 0
Hi....
Above code is not working for me
please find attached image for reference
kindly suggest what to do








Master BOQ - Copy - Copy.xlsx
ABCDEFGHIJKLNO
1
2
3 ESTIMATION SHEET
4
5
6
7Sr. No.DescriptionC/SSizeSch / TypeL (mm)W (mm)Thk/Ht (mm)OD (mm)ID (mm)MOC (mm)Qty (Nos)Weight (Kg) Amount
81ExampleRectangular12341234123412341234 
92ExampleCircular12341234123412341234 
103ExampleISA65 x 65 x 8123412341234123412340.00
114ExamplePipes_80NB20123412341234123412340.00
125ExampleFastner12341234123412341234 
136ExampleCircular12341234123412341234 
147ExampleFastnerM12 x 65123412341234####12340.00
158ExampleFlange_.40NBWNRF0.00
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A8:O17Cellcontains a blank value textNO
It is perfectly working for "Flanges" only
 
Upvote 0
I tested the code on the data you posted and it works as designed, locking the cells that are hard coded in the macro. The code refers to some cells in row 1 that are blank. Is that what you want? Did you unprotect all the cells in your sheet before trying the macro? Explain in detail how it is not working for you referring to specific cells, rows and columns using a few examples from your data.
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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