Solved

Macro for selection choices

Posted on 2016-08-08
7
39 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 28

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 28

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 28

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 28

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

11 Experts available now in Live!

Get 1:1 Help Now