VBA: Worksheet_Change(ByVal Target As Range) in 2 cells + copy and paste to 2 Columns

  • Hi,
    I'm having a excel sheet that should search Column 'B' from cell value i put in 'G4',
    everytime i put a value in cell G4.


    Afterwards, if finding the value in Column 'B' (lets say example 'B14') it should put the cellvalue matched, in the same row, in column 'G' (example 'G14').


    I have done that by this code (i'm a noob, so bare with me) :



    This is the seeking and mark sub:



    But my main problem is, can i somehow get this to work from 2 cells.
    If any changes in G4 or I4, its should do the same search from either the cell value in G4 or if the change is in I4, it should do the search from that cell value, in Column B,
    but if the cellchange is in I4, it should return the value in Column I (example I14, if found in B14)


    Is that possible ?


    Regards
    Muggi

  • Re: VBA: Worksheet_Change(ByVal Target As Range) in 2 cells + copy and paste to 2 Col


    Okay got help from another forum (thx to patel45).
    this is the code to use:

  • Re: VBA: Worksheet_Change(ByVal Target As Range) in 2 cells + copy and paste to 2 Col


    I think there is something wrong.
    If I have 123 in cell B14 and with cell G4 search 23 the macro will match and place 23 in cell G14.
    Same thing if I have ABC in cell B14 and search AB it will match and copy AB in cell G14.
    It should match only if I search 123 or ABC.

  • Re: VBA: Worksheet_Change(ByVal Target As Range) in 2 cells + copy and paste to 2 Col


    muggi,


    If you are cross-posting a query at another forum then please post a link to your post at that forum. (See the link in my signature for the reason why we ask that posters do this). Thank you.

  • Re: VBA: Worksheet_Change(ByVal Target As Range) in 2 cells + copy and paste to 2 Col


    Sorry, didn't know the reason for posting links when crossposting..


    here is the final solution:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!