Solved

Macro for selection choices

Posted on 2016-08-08
7
47 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 30

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 30

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 30

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 30

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

762 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