Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Activating desired cell

    Hello there,

    I need help with one functionality in Excel. I have 4 columns. Column A is columne where values are predefined. In column B I'm entering random values. Column C is column with lookup function which returns value from column A if it is found in column B. To be more clear here is how it looks:


    A B C D
    1 aa ju aa
    2 ab ae
    3 ac af
    4 ad lo
    5 ae pi ae
    6 af ck af
    7 ag aa
    8 ah rn

    What i want to do with column D is this:
    When i enter 'aa' and VLOOKUP return value in C column, I want Excel automatically position in D column in row where value is entered. So, if I enter 'aa', 'aa' will be written in C1 cell. After this i done, I would like Excel position in cell D1. If I enter 'af', 'af' will be written in C6 cell. After this, I would like Excel position in cell D6.

    So, my question is, how to select desired cell when value in other cell is entered? If needed i can upload my workbook.

    Thank you all,
    Dev.

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    I don't understand. Where are you entering the value that triggers the selection of a different cell? Also do you want the value in C to cease being the lookup formula and being the value you enter? Please elaborate on what cells have values, which have formulas, which formulas will change and what entry you will make to trigger the macro to move the selected cell.

    Steve

  3. #3
    New Lounger
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sdckapr View Post
    I don't understand. Where are you entering the value that triggers the selection of a different cell? Also do you want the value in C to cease being the lookup formula and being the value you enter? Please elaborate on what cells have values, which have formulas, which formulas will change and what entry you will make to trigger the macro to move the selected cell.

    Steve
    Hi Steve.

    I uploaded my excel. Inside are explanations so I think it will be more clear (at least I hope so ).

    Thank you,
    Dev.
    Attached Files Attached Files

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Dev,

    I think this code will do what you are after. Place the code in the Sheet1 Module.

    Note: The code will fire for the entire Column B! If you want to limit it you can change the line:
    Set isect = Application.Intersect(Range("B:B"), Target)
    to reflect a specific number of rows via "B1:B100" or create a namedrange and use it.

    HTH

    Code:
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
       Dim isect As Range
       
       Set isect = Application.Intersect(Range("B:B"), Target)
       If isect Is Nothing Then
         Exit Sub
       Else
         '***Prevent following code from refiring Change Event ***
         Application.EnableEvents = False
         Target.Offset(0, 2).Select
         Application.EnableEvents = True '*** Reset Events ***
       End If
    
    End Sub
    Last edited by RetiredGeek; 2014-10-06 at 10:02.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. The Following User Says Thank You to RetiredGeek For This Useful Post:

    dev11111 (2014-10-06)

  6. #5
    New Lounger
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you very much RG, you are great!

    I checked and its almost perfect. B:B is fine for me . What I would like to change (if this can be done) is that activated cell is the one to the left of the value where lookup returns. As you see, 'aa' is returned in C1. Can activated cell be D1 instead of the cell which is in row where value is inputed? If you open my excel it would be easier to understand me.

  7. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Dev,

    Ok here's your file (changed to .xlsm to allow macros). I've commented out the line that moves to Col D in same row and inserted a line that always selects D1!
    DEV11111 ExcelExample.xlsm
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. The Following User Says Thank You to RetiredGeek For This Useful Post:

    dev11111 (2014-10-07)

  9. #7
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,634
    Thanks
    115
    Thanked 649 Times in 592 Posts
    Dev,

    If needed, this code will select the cell right adjacent to the cell in column C which was the result of the Vlookup.

    The match function finds the row of the value in column A that matches the inputted value from column B then uses the row to select the adjacent cell in column D

    adjacentCell.png

    Code:
        On Error Resume Next
        Dim LastRow As Integer
        Dim Row As Integer
        If Target.Cells.Count > 1 Then Exit Sub
        LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        If Not Intersect(Target, Range("B1:B" & LastRow)) Is Nothing Then
            Row = WorksheetFunction.Match(Target, Range("A:A"), 0)
            Cells(Row, 4).Select
        End If
    Attached Files Attached Files

  10. The Following User Says Thank You to Maudibe For This Useful Post:

    dev11111 (2014-10-07)

  11. #8
    New Lounger
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Maudibe View Post
    Dev,

    If needed, this code will select the cell right adjacent to the cell in column C which was the result of the Vlookup.

    The match function finds the row of the value in column A that matches the inputted value from column B then uses the row to select the adjacent cell in column D

    adjacentCell.png

    Code:
        On Error Resume Next
        Dim LastRow As Integer
        Dim Row As Integer
        If Target.Cells.Count > 1 Then Exit Sub
        LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        If Not Intersect(Target, Range("B1:B" & LastRow)) Is Nothing Then
            Row = WorksheetFunction.Match(Target, Range("A:A"), 0)
            Cells(Row, 4).Select
        End If
    Great Maudibe!!!! Thats what I was looking for.

  12. #9
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,634
    Thanks
    115
    Thanked 649 Times in 592 Posts
    Oops, got cut off.

    That goes in the Worksheet_Change subroutine of the sheet module.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error Resume Next
        Dim LastRow As Integer
        Dim Row As Integer
        If Target.Cells.Count > 1 Then Exit Sub
        LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        If Not Intersect(Target, Range("B1:B" & LastRow)) Is Nothing Then
            Row = WorksheetFunction.Match(Target, Range("A:A"), 0)
            Cells(Row, 4).Select
        End If
    End Sub

Posting Permissions

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