Solved

Macro to populate cells or allow for validation input

Posted on 2016-08-01
10
34 Views
Last Modified: 2016-08-01
EE Pros,

I have a Worksheet that has a 3 dropdown cells.  In the first cell, if you select "Consistently", then the other two cells identified, are auto. populated.  If "Consistently" is not selected, you can put any other choice from the list box in the cells.

That's it!  Much thanks in advance.

B.
Macro-for-populating-Cells.xlsm
0
Comment
Question by:Bright01
  • 5
  • 5
10 Comments
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41737397
Your request is not clear, at least to me.
Would you please elaborate it to let us know your exact requirement?
0
 

Author Comment

by:Bright01
ID: 41737414
Neeraj,  my apologies.

I have three cells where there are list box drop downs.  In the first cell (E8) you can select 6 different choices.  What I want a Macro to do is that if the first choice in the selection for E8, "Consistently", is selected, I want it to automatically place the choices for the other two boxes.  For F8, it would place "Achieve" in the box and for F10, "n/a".  IF "Consistently" is not selected for E8, then any dropdown selection can be choosen for all three boxes.

Does that make sense?

B.
0
 
LVL 28

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41737437
Place the following code on Sheet1 Module. To do that, right click the Sheet1 Tab --> View Code and place the following code into the opened code window.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "E8" Then
    Application.EnableEvents = False
    Range("F8").Value = "ACHIEVE"
    Range("H8").Value = "n/a"
    Application.EnableEvents = True
End If
End Sub

Open in new window

Does this help?
0
 

Author Closing Comment

by:Bright01
ID: 41737466
Neeraj,

You nailed it!  Thank you very much. Great job.  Works perfectly.

B.
0
 

Author Comment

by:Bright01
ID: 41737551
Neeraj,

Quick question.  Let's say I need the same capability down the E column, say E8:E26, how would I set up the macro to adapt to choices in other E selections between that range?  In other words, if I went to E25 and selected "Consistently" in E25, how would I get it to properly populate the other F & H25 cells?

B.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41737569
You're welcome. Glad to help.

In that case replace the existing code with the following one...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("E8:E26")) Is Nothing Then
    Application.EnableEvents = False
    Target.Offset(0, 1).Value = "ACHIEVE"
    Target.Offset(0, 3).Value = "n/a"
    Application.EnableEvents = True
End If
End Sub

Open in new window

0
 

Author Comment

by:Bright01
ID: 41737597
This works, but one small problem.  In the original ask, I had said, "if the first choice in the selection for E8, "Consistently", is selected...."  The way the macro is presently written, if any selection is made in E8:E26, it populates F8:26 with "Achieve".  It's only suppose to do that when "Consistently" is choosen in the E Cells.

B.
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41737613
Ah.. okay got it.
Please try the below code.....
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("E8:E26")) Is Nothing Then
    If Target = "CONSISTENTLY" Then
        Application.EnableEvents = False
        Target.Offset(0, 1).Value = "ACHIEVE"
        Target.Offset(0, 3).Value = "n/a"
        Application.EnableEvents = True
    End If
End If
End Sub

Open in new window

0
 

Author Comment

by:Bright01
ID: 41737673
Thank you!  Now it works perfectly.

B.
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41737676
You're welcome. :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

747 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

12 Experts available now in Live!

Get 1:1 Help Now