• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Create Range Name loop

Svmaxcel

Member
I had a list with Emp name and manager
i wanted to create Name range, for combo box usage, but there were many common manager names.
So i thought of using pivot tableto create name rang using VBA
please check the attached file
After getting discharged from hospital, my memory has become very dull, so i am hardly able to remember much

I want to create a loop that will create Name Range from pivot table and Stop when the pivot table will end
Code:
Sub Macro1()
    Range("F3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.CreateNames Top:=True
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.CreateNames Top:=True

End Sub
 

Attachments

  • Book1.xlsm
    15.9 KB · Views: 4
Try this code:

Code:
Sub Setup_Names()
   
    Range("F3").Select
   
    Do Until Selection.Row = 1048576
      Range(Selection, Selection.End(xlDown)).Select
      Selection.CreateNames Top:=True
      Selection.End(xlDown).Select
      Selection.End(xlDown).Select
    Loop
End Sub
 
Thanks for your reply
It worked well.

I am using 2 Combo box, based on 1st box, Combo box 2nd will filter data.
I have used case select for this.

Sub Combobox1.change
Case "Fruits"
Me.Combobox2 = "Mango"
And so on....
End sub

This is working fine
Now I want to know, if there is any new category, how can I use Case select.
 
Is this related to the previous question ?

If not please start a new thread and attach a sample file
 
Example attached
so if a new Manager name is added in the table and pivot table is refreshed, new Name range for th manager will be created automatically, changes will reflect in Combbox1, but in case of Combobox 2, there is no Case Select...
 

Attachments

  • Book1.xlsm
    23.2 KB · Views: 2
This question isn't related to the first question and so should have been posted in a new Thread

This is so that there is no confusion when looking for posts

Now try the following code instead of yours

Code:
Private Sub Combobox1_Change()
Me.ComboBox2 = ""
Me.ComboBox2.RowSource = Range(Me.ComboBox1).Address

End Sub
 
Works perfectly for me

I replaced the enter Sub Combobox1_Change() not just the code

Next time, post your file and post details of what isn't working and what should it should be doing
 

Attachments

  • Book1 (Hui).xlsm
    29.4 KB · Views: 5
Works perfectly for me

I replaced the enter Sub Combobox1_Change() not just the code

Next time, post your file and post details of what isn't working and what should it should be doing

This worked like a charm, howwver there is small issue here
the example which i posted only had firstname.

So i just added last name to some names, Refreshed Pivot and ran VBA for Comobox, but didnt workout

Rebriefing some more issues
Issue # 1 Post no 2 VBA gives an error as it tried to go beyond last Row of excel(A1048576), it creates name ranges, but gives an error.

Issue # 2 It creates Name Ranges, but overlaps the old Named ranges.
so it keeps the old name as well as new names (i guess it would be better to delete old name ranges in column A)

Issue # 3 While we are using full name with a space in between, excel adds an Underscore to replace the space, due to which they are not recognized and gives error while using VBA, I guess we can use INDIRECT, but no clue of how to use it

Attaching updated file
 

Attachments

  • Book1 (Hui).xlsm
    30.3 KB · Views: 2
Back
Top