+ Reply to Thread
Results 1 to 10 of 10

Validation list to change columns values

  1. #1
    Registered User
    Join Date
    03-24-2009
    Location
    In my own little world
    MS-Off Ver
    Excel 2007
    Posts
    5

    Validation list to change columns values

    So I've got a drop down list in cell B73 That when I change the selection I want it to copy the cells below it (B74:B94) from one of the charts above it. Through the power of Google I found this: http://www.eggheadcafe.com/conversat...eadid=29484871, someone who had the same need as me, and edited it accordingly to my needs. It however, is not working. I started with Case 1-7 and changed them thinking they need to be the same as the list but that hasn't fixed it either. File is attached, and below quote is what the VBA coding currently says.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Application.Intersect(Range("B73"), Target) Is Nothing Then
    Select Case Target.Value
    Case Human: Range("B74:B94").Value = Range("B2:B22").Value
    Case Elf: Range("B74:B94").Value = Range("C2:C22").Value
    Case Drow: Range("B74:B94").Value = Range("D2:D22").Value
    Case Dwarf: Range("B74:B94").Value = Range("E2:E22").Value
    Case Orc: Range("B74:B94").Value = Range("F2:F22").Value
    Case Centaur: Range("B74:B94").Value = Range("G2:G22").Value
    Case Gnome: Range("B74:B94").Value = Range("H2:H22").Value
    End Select
    End If
    End Sub
    Attached Files Attached Files
    Last edited by avisamo; 03-26-2009 at 07:21 AM. Reason: solved

  2. #2
    Registered User
    Join Date
    03-24-2009
    Location
    In my own little world
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Validation list to change columns values

    Not a single reply?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Validation list to change columns values

    I see a bunch of undeclared, uninitialized variables that all default to Variants with a value Empty.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Validation list to change columns values

    Try this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-24-2009
    Location
    In my own little world
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Validation list to change columns values

    That didn't work, selecting things in the box still don't change anything. Also "I see a bunch of undeclared, uninitialized variables that all default to Variants with a value Empty." was complete jargon to me, I've never gone into actual programming in excel, just dove into it headfirst since I couldn't think of any other way to do this, one too many variables for a 3d mapper.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Validation list to change columns values

    ... was complete jargon to me,
    That's the nature of programming, I'm afraid.

    VBA, like some other languages, does not require you to declare variables -- it will create them on the fly as they're used. The type of variables it creates are all-purpose types called Variants, and their value is Empty until they are assigned to something. That sounds great in principle, but it's error-prone, as you've discovered. Putting Option Explicit at the top of every module requires you to declare variables.
    Please Login or Register  to view this content.
    I plugged it into your workbook, and it ran fine. Code that responds to worksheet events has to go in the sheet module. See attached.

    EDIT: BTW, you certainly don't need code to do this -- you could use lookup functions.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-24-2009
    Location
    In my own little world
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Validation list to change columns values

    ... figures. I'm always going around my back to get to my elbow... So you would suggest I use lookup function instead? If so I'll go look that up instead. The only reason I was doing it this way was because this is the only thing I could find via googling.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Validation list to change columns values

    Delete the code, then in B74 and copy down,

    =HLOOKUP(B$73, $B$1:$H$22, ROWS(B$73:B74), FALSE)

  9. #9
    Registered User
    Join Date
    03-24-2009
    Location
    In my own little world
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Validation list to change columns values

    Wow that is a lot better, I actually understand whats being done there, so I can modify it if need be. Also macros were disabled that is why the vba wasn't working for me V_V.

    Thanks for the help!

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Validation list to change columns values

    You’re welcome. Would you please mark the thread as Solved?

    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1