Consulting

Results 1 to 17 of 17

Thread: Dynamic range that change variables

  1. #1
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location

    Question Dynamic range that change variables

    Hi
    I´ve been searching for a solution for this problem for a long time now and hope that you guys can help me out. I´m just a beginner in VBA so it may be easy.

    I have a sheet with a column of Products, to each Product I have different values in other columns on the same row. Rows are deleted and added.
    I want to have a userform with a combobox that are populated from the Product column and depending on wich choice the user makes I want to get values from other columns on the same row.
    I guess it must be a way to have a dynamic range to populate the combobox and then use the Offset funktion to get values from the other columns but can´t figure it out. Could anybody help me with this ? I would really appreciate it !!
    Many thanks

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,075
    Location
    Please attach a sample workbook, by clicking on Go Advanced, scroll down to Manage Attachments and follow the prompts from there.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular
    Joined
    Feb 2012
    Posts
    36
    Location
    1) Create a sheet which has a master list of products
    2) Create a named range for that list
    3) Select the cell you want to have a dropdown. In the Data Validation, select List in the first dropdown and type =RangeName in the second dropdown.

    Hope this helps

  4. #4
    VBAX Regular
    Joined
    Feb 2012
    Posts
    36
    Location
    If it is a user form you can use the RowSource property and give the name of the range. Kindly refer to this site
    http://support.microsoft.com/kb/161598

  5. #5
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    Maybe I wasn´t clear enough, I have no problem populate a combobox from a cell range, the problem is to use an dynamic range to the combobox that refers to the adjacent cells in the row. Hope my file describes it self.
    Thanks again!
    Attached Files Attached Files

  6. #6
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    No one have any ideas on this?? I really been searching a lot on this everywhere and I think it should be an quite easy task, but maybe not?

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Private Sub ComboBox1_Change()

    Dim r As Range
    Set r = Columns(1).Find(ComboBox1).Resize(, 3)

    Label6.Caption = r(1)
    Label7.Caption = r(2)
    Label8.Caption = r(3)

    End Sub[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location

    Haven´t tried it yet but I´m really happy to get an answer and it seem that simple that I wanted it to be! Will try it , thanks a bunch !!

  9. #9
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location

    Thank you so very much !!! Works exactly as i wanted, easy to add and delete rows without changes in the code!!
    Thanks again !!!

  10. #10
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    How do I mark the thread as solved?

  11. #11
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    Hi, I tried to use this method but it seems to be some problem with it, some times when I shall make the choice in the combobox I get Runtime error 91, is there an solution to this problem?

    B.R / Bengt

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What value are you selecting in the combobox?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    I have a sheet with products in column A, which I populate the combobox with, to each product I have 16 different values in other columns that belongs to that product. So I want to select a product in the combobox and get values to variables from that choice. What is strange is that sometimes it works fine but sometimes I get the runtime error??

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Your example workbook seemed problem free, so post the real book and tell us how to re-create the error.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    This is under construction but I made different tests and some works and some not. To populate the combobox, press "Maskin1" or "Maskin2" button
    B.R/ Bengt
    Attached Files Attached Files

  16. #16
    If you would change

    Set r = Columns(1).Find(ComboBox1).Resize(, 17)
    To

    Set r = Sheets("Data1").Columns(1).Find(ComboBox1).Resize(, 17)
    Would that make a difference?

  17. #17
    VBAX Regular
    Joined
    Feb 2012
    Posts
    10
    Location
    Looks good so far! Aah, hope it was that simple! Thanks a lot!
    B.R/Bengt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •