Solved

Macro for selection choices

Posted on 2016-08-08
7
43 Views
Last Modified: 2016-08-08
EE Pros,

I have a simple WS that should have 2 options for a selection in two cells.  If the button/macro is currently selected,  it produces a 1 or a 2.  If it is 1, then it should allow the user to select a choice by a predetermined drop box.  If 2, it should take the selection from another set of two cells.

Attached is the WS.

Thank you in advance.

B.
Macro-to-drive-selection.xlsm
0
Comment
Question by:Bright01
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41747089
Place the following code on Maturity_Model Sheet module for change event and see if this is what you were trying to achieve....
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Application.ScreenUpdating = False
If Not Intersect(Target, Range("D29:D30")) Is Nothing Then
    Application.EnableEvents = False
    If Range("L49").Value <> 1 Then
        Application.Undo
        Range("D29").Value = Range("L64").Value
        Range("D30").Value = Range("M64").Value
    End If
    Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub

Open in new window

1
 

Author Comment

by:Bright01
ID: 41747149
Neeraj,

Greetings and thank you for jumping in.

I think I may not have been as clear as I should have been in describing what I was looking for.  I added your code and it does work..... but not exactly how I imagined it would.  And it may have to do with the enable events line.

When you select the button (Use Selection), I'm trying to get it to toggle between the choices.  If there is no selection from the dropdown or there is no selection from L64, M64, the cells in D29 and E30 would simply be blank.

Does that make sense?  Sorry I wasn't more clear up front.  Hopefully that is an easy fix.

B.
0
 
LVL 29

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41747167
Does this work for you?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Application.ScreenUpdating = False
If Not Intersect(Target, Range("D29:D30")) Is Nothing Then
    If Target <> "" Then
        Application.EnableEvents = False
        If Range("L49").Value <> 1 Then
            Application.Undo
            Range("D29").Value = Range("L64").Value
            Range("D30").Value = Range("M64").Value
        End If
        Application.EnableEvents = True
    End If
End If
Application.ScreenUpdating = True
End Sub

Open in new window

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:Bright01
ID: 41747181
Not quite.  It still doesn't "toggle" between the two selections when the button is pushed.

B.
0
 
LVL 29

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41747215
Well I am not able to understand your requirement correctly.
Do you have issue with the toggle button or the change event code?
BTW I have inserted a toggle button on the sheet, please use that button and let me know what else you want it to do.
Macro-to-drive-selection.xlsm
0
 

Author Closing Comment

by:Bright01
ID: 41747249
Neeraj,

Your "fix" is perfect!  Thank you very much!

B.
0
 
LVL 29

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41747257
You're welcome. Glad your issue is fixed. :)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now