• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Problem with multiple-select Drop down list|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Problem with multiple-select Drop down list|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosProblem with multiple-select Drop d…
sp_PrintTopic sp_TopicIcon
Problem with multiple-select Drop down list
Avatar
Tamara Assoma

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 9, 2022
sp_UserOfflineSmall Offline
1
November 10, 2022 - 12:31 am
sp_Permalink sp_Print sp_EditHistory

Hi,

While using the codes for multiple select drop down list, i got some problems the first one is: when i use codes for another thing in: (Private Sub Worksheet_Change(ByVal Target As Range))

It will not work because of this:

"If more than 1 cell is being changed"

If Target.Count > 1 Then Exit Sub

If Target.Value = "" Then Exit Sub

so i deleted these codes and when i need more than one cell with muliple-select i repeat the whole codes again but it works. And only this way other codes could work.

The other problem that i could not fix is: for example i choose data1, data2, data3 from the list and i want to delete them all but i do not want to select one after the other to delete them. so i want easily to press delete, but when i do that, codes from VBA do not work anymore and i have to close the excel file and reopen it to work again.

thanks for your time

regards

Tammy

p.s.: attached you will find the codes in text-file

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
2
November 10, 2022 - 10:29 am
sp_Permalink sp_Print

Hi Tammy,

I'm not sure what you mean by i got some problems the first one is: when i use codes for another thing

Can you provide the file you are using and explain what you are trying to do?

The purpose of this code

If Target.Count > 1 Then Exit Sub

Prevent the code running of more than 1 cell is being changed at the same time.  If you are using a drop down data validation list, then you should only ever be changing 1 cell at any time, so there's no need to remove that line.

If Target.Value = "" Then Exit Sub

If the cell value has been deleted, then exit the code, there's no need to run anything.  If you have deleted this line, that is why you are finding that the code doesn't run when you delete the cell contents.

If what you are trying to do is run the code for 2 different data validation lists then you need to change this line to account for the 2nd dv range

If Not Intersect(Target, ActiveSheet.Range("DV_Range")) Is Nothing Then

If you can supply your file and explain exactly what it is you want to do, I'll see if I can come up with a solution.

Regards

Phil

Avatar
Tamara Assoma

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 9, 2022
sp_UserOfflineSmall Offline
3
November 10, 2022 - 8:47 pm
sp_Permalink sp_Print sp_EditHistory

Hi Phil,

I'm not allowed to send my original file but I attached an example file for the problem 

in this example, i used the codes:

If Target.Count > 1 Then Exit Sub

If Target.Value = "" Then Exit Sub

and every thing works fine but the next codes: 

If Range("C6") = "yes" Then
[9:11].EntireRow.Hidden = False

Else
[9:11].EntireRow.Hidden = True

End If

are not working

 

regards,

Tamara

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
4
November 15, 2022 - 9:30 am
sp_Permalink sp_Print

Hi Tamara,

You need to add a 'trap' to check for the cell that is being changed.  As you want to check the value in C6 when it is changed, you need to add code to check for a change to that cell, like this

 

If Not Intersect(Target, ActiveSheet.Range("C6")) Is Nothing Then

If Range("C6") = "yes" Then

[9:11].EntireRow.Hidden = False

Else

[9:11].EntireRow.Hidden = True

End If

End If

 

See attached file.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Tamara Assoma

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 9, 2022
sp_UserOfflineSmall Offline
5
November 15, 2022 - 6:42 pm
sp_Permalink sp_Print

Thanks alot that was a big help.

But if i want to use data1, data2... in cell C4 to determine hide or unhide rows then an error will occur.

please see the attaced file

regards

Tammy

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
6
November 15, 2022 - 9:10 pm
sp_Permalink sp_Print

Hi Tamara,

Running the code in the last file you provided does not generate any errors.

Could you please describe in detail exactly what it is you are trying to do.  Maybe provide a file or an image showing an example of the final result you want.

Since your initial request, you've described a number of different issues, which i have resolved, but I'm still not clear what it is you are actually trying to do.

Regards

Phil

Avatar
Tamara Assoma

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 9, 2022
sp_UserOfflineSmall Offline
7
November 15, 2022 - 9:33 pm
sp_Permalink sp_Print

I'm sorry for not explaining myself currectly.

For example when I choose data1 in C4 then the row with data1 (B13) appears (but C4 reset itself and i can't see data1 in C4) and when i choose data2 the row with data2 (B14) appears but the row with data1 (B13) disappears

I want to see both data1 and data2,  only the last one i chose will appear because C4 keep resetting itself 

 

regards,

Tamara

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
8
November 16, 2022 - 1:57 pm
sp_Permalink sp_Print

OK I think I know what you mean.  The code you've entered is interfering with my code that checks the selection from the validation list.

You just need to move this after my code so the DV changes are dealt with correctly, then your code can run doing what you want.

If you stepped through the code you could see that this was happening.  Please read these posts which discuss debugging VBA code:

Debugging VBA Code

More Tips for Debugging VBA Code

regards

Phil

Avatar
Hans Hallebeek
the Netherlands
Member
Members
Level 0
Forum Posts: 71
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
9
November 16, 2022 - 5:54 pm
sp_Permalink sp_Print

Hi. sorry to butt in like this but I made some minor changes to pgt-example-3 to avoid the error in C4 when there is nothing to split and als when the target is cleared.

Avatar
Tamara Assoma

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
November 9, 2022
sp_UserOfflineSmall Offline
10
November 16, 2022 - 6:32 pm
sp_Permalink sp_Print

@ Philip Treacy

Thanks alot, the problem war exactly this. Thanks for the big help.

 

@ Hans Hallebeek

Thanks for your post, this solution also helps me alot.

 

best regards

Tamara

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOnlineSmall Online
11
November 17, 2022 - 10:33 am
sp_Permalink sp_Print

No worries Tamara

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Carlos Ferreira, Chandler Davis, baber Tufail
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
drsven
Annie Witbrod
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27211

 

Member Stats:
Guest Posters: 49
Members: 31880
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.