Dynamic chart ranges populated from named ranges as selected in nested indirectly sourced validation lists.

Phill Jones

New Member
Joined
Nov 2, 2013
Messages
5
Hi all,

Long time reader - first time poster.

As the rather cryptic subject says, I'm trying to dynamically populate ranges to facilitate dynamic charts being generated.

I use excel 2010 at work, and 2011 for mac at home.

I have an example spreadsheet, but I don't know if I can upload it here. It makes far more sense than I can ever hope to make in using words, but I will do my best to put it in a nutshell:

I want any selection made in a dependent validation list which contains a list of named ranges to trigger a worksheet_change event which copies the range the selection points to and pastes it into a dynamic range in another column, beginning as a specified cell.I've tried using this, put together from some code examples from similar, but different issues.

Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">[COLOR=#00008B]Private[/COLOR] [COLOR=#00008B]Sub[/COLOR] Worksheet_Change([COLOR=#00008B]ByVal[/COLOR] Target [COLOR=#00008B]As[/COLOR] Range) 
 [COLOR=#00008B]If[/COLOR] [COLOR=#00008B]Not[/COLOR] Intersect(Target, [COLOR=#00008B]Me[/COLOR].Range([COLOR=#800000]"B2"[/COLOR])) [COLOR=#00008B]Is[/COLOR] [COLOR=#800000]Nothing[/COLOR] [COLOR=#00008B]Then[/COLOR] 
   Range(Range([COLOR=#800000]"B2"[/COLOR]).Value).Copy 
   Range([COLOR=#800000]"P2"[/COLOR]).Paste  
[COLOR=#00008B] End[/COLOR] [COLOR=#00008B]If
[/COLOR][COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Sub
[/COLOR]</code>

Trouble is, I don't really understand this code. It doesn't appear to do anything when I make a worksheet change in "B2", but I don't know exactly what it is that I don't understand to ask for more specific help. I'm a bit stumped, and wish I could better articulate what help I need. I suspect that perhaps the fact that "B2" is validated from an indirect source might cause headaches?

Maybe there's a simpler way to achieve what I'm trying to do.

Thanks to anyone who can help (or understand what I'm attempting to do)

Phill
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
So how do you know it's not firing? If you put this at the beginning:

Code:
MsgBox "Change"

do you see a pop up when you change what's in B2?
 
Upvote 0
no, no popup. I don't actually understand how this code is monitoring B2 for a change. The syntax is a bit confusing. I don't really enjoy using code that I don't understand the operation of for this reason.
 
Upvote 0
Does this make it clearer?

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$2" Then
        Range(Range("B2").Value).Copy
        Range("P2").Paste
    End If
End Sub

How are you changing B2 exactly?
 
Upvote 0
B2 is a validation list. Its source is an =indirect which results in a named range itself. The first validation box is for "State". B2 is dependent on what value is in B1. B2 is for "Offices". The items in its list are all named ranges themselves. Hence trying to copy the range and paste it into the dynamic range for the chart. Does that make sense?

Target.address makes sense. So that just means it's looking for target as range, that range being B2. Any change to B2 proceeds with the code. I suppose I ought to put an if not change, exit sub procedure too.
 
Upvote 0
You don't need an Else for that scenario. Is the event firing now? If not type this in the Immediate Window in the Visual Basic Editor:

Application.EnableEvents = True

and press Enter.
 
Upvote 0
I've got it to fire! *Red face* I had the module on General. Sigh. On Worksheet and Change, it works.

Thanks so much for your help. I'm sure that this won't be my last issue requiring some assistance.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
Range(Range("b2").Value).Copy ([P2])
End If
End Sub

This copies the named range into the target as planned.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top