Hiding Columns VBA & Validation Dropdown Lists

PEC-Memphis

New Member
Joined
Apr 15, 2009
Messages
19
I posted a question a week or so ago, where a VBA would run on one worksheet but not another. It seems that I didn't understand the problem. After goobing around some more, the problem is related to using the validation pull-down. Here is the VBA:
Private Sub Worksheet_Change(ByVal Target As Range)

If Range("D5") <> "DBS" Then
Columns("J").EntireColumn.Hidden = True
Else
Columns("J").EntireColumn.Hidden = False
End If

End Sub

Seems simple enough?

If I manually enter "DBS" in cell D5, col "J" is unhidden, if I manually enter anything else in D5 col "J" is hidden; ie. the VBS works as intended.

Here's the problem: If I enter "DBS" using the validation dropdown it doesn't work, ie col "J" remains in the current state of "hidden-ness", unless I put the cursor in the formula bar after "DBS" and click on the check mark or hit enter.

I need for the users to be able to use the drop down list because the value in D5 also is used with VLOOKUP function to enter data in other cells from a library of data.
 
Last edited:
Unfortunately, I do not know what would cause this issue. I know this is a silly question, but I will ask anyway. You are only using one or the other of the two codes, correct? The only reason that I can think of why the new one does not cause the issue is the use of the Intersect(Target) entry. It should limit/focus where the code is looking.

Thanks for all of your help, I really appreciate it.

Yes, I am only using one, or the other, but not both at the same time.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,833
Messages
6,127,153
Members
449,366
Latest member
reidel

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