based on column value, unable-disable column values

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Hi All,

column A - and below is the a7Col BCol CCol D - contain list - data validation
blank100disabledisable
50100disabledisable
disabledisable100USD
disabledisable50INR

above is my current scenario. On cell move event, i need vba code.
If values gets enter in either a or b column cell then c and d both should get disable.
If values gets enter in either c or d column cell then a and b both should get disable.

Can anyone help with code pls..
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
@Rick Rothstein or @Joe4 Sir, any guidance from you pls..

I always get successful output from you on my almost every query from you.. please look the query and guide.. Thank You.. :)

Sincerely regards,
vbabeginer
 
Upvote 0
I am sure that Rick will probably come up with something "short and sweet" a little later (he usually does), the following should do what you want.
Just right-click on the Sheet tab name at the bottom of the sheet, select "View Code", and paste this code into the VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim c As Long

'   Only run if a single cell is manually updated
    If Target.CountLarge > 1 Then Exit Sub
    
'   Only run if update is in columns A-D, and after row 6
    If Target.Column < 5 And Target.Row > 6 Then
'       See if a non-blank entry was entered in the cell
        If Target.Value <> "" Then
'           Determine which columns to update
            If Target.Column > 2 Then
                c = 1
            Else
                c = 3
            End If
'           Determine update
            If LCase(Target) <> "disable" Then
                Application.ScreenUpdating = False
                Range(Cells(Target.Row, c), Cells(Target.Row, c + 1)) = "disable"
                Application.ScreenUpdating = True
            End If
        End If
    End If

End Sub
I documented the code to explain what each step is doing.
 
Upvote 0
Very first, Thank You so much for your kind attention. Appreciate your reply.. ?

And, 2nd You're amazing.. code is really nice..
but let me explain one more time..

if user enter value in either col A or in col B then user should not get to enter anything in Col C and D cell.
"Disable" means, unable to enter anything in another pair.

if user enter value in either Col C cell or Col D cell then A and B col cell value should not get to enter.

:giggle:

one thing i missed in 1st post.. i.e. I want to add list option in col D. List will be currency like e.g.. USD, INR..
 
Upvote 0
if user enter value in either col A or in col B then user should not get to enter anything in Col C and D cell.
"Disable" means, unable to enter anything in another pair.
Then the link that SamitNair gave you should do what you want.
Note that the password protection step is optional. If you do not want to password protect it, then just remove those lines of code from what it shown.
However note that if you do that, the user can easily unlock the cells on their own, if they try.
 
Upvote 0

Forum statistics

Threads
1,214,884
Messages
6,122,082
Members
449,064
Latest member
MattDRT

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