Solved

Macro to populate cells or allow for validation input

Posted on 2016-08-01
10
40 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 30

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 30

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
Technology Partners: 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 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
 
LVL 30

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 30

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 30

Expert Comment

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

Featured Post

Industry Leaders: 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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

713 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