Consulting

Results 1 to 6 of 6

Thread: Automatic Select Based on Cell Value

  1. #1

    Automatic Select Based on Cell Value

    Hello again!

    I'm having difficulty with my select code:

    [VBA]
    Sub SelectItem()
    If Range("D2") = "A" Then
    Range("A16").Select
    Else
    If Range("D2") = "B" Then
    Range("A31").Select
    Else
    If Range("D2") = "C" Then
    Range("A46").Select
    Else
    If Range("D2") = "D" Then
    Range("A73").Select
    End If
    End If
    End If
    End If
    End Sub
    [/VBA]


    I just want to automatically select a cell when I select an item in Column D2. But unfortunately my code is not working.

    I attached a dummy file for easier understanding.

    Please help!

    Thanks!!!

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    try changing it to a select case. also, put it in the worksheet change event
    Peace of mind is found in some of the strangest places.

  3. #3
    Ok I'll try...

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    try this:

    [VBA]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Select Case Range("D2")
    Case "A"
    Range("A16").Select
    Case "B"
    Range("A31").Select
    Case "C"
    Range("A46").Select
    Case "D"
    Range("A73").Select
    End Select
    End Sub
    [/VBA]
    Peace of mind is found in some of the strangest places.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Should be Target Austen

    [vba]

    Select Case Target
    [/vba]
    ____________________________________________
    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

  6. #6
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    [VBA]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Select Case Target
    Case "A"
    Range("A16").Select
    Case "B"
    Range("A31").Select
    Case "C"
    Range("A46").Select
    Case "D"
    Range("A73").Select
    End Select
    End Sub [/VBA]

    Thanks for spotting that Bob.
    Peace of mind is found in some of the strangest places.

Posting Permissions

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