Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Macro for selection choices

Posted on 2016-08-08
7
Medium Priority
?
51 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 33

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 33

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 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 33

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

773 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