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


    You are right, I just explained the problem in the other forum.
    It would be a good idea to only get a match on the whole cell and not just a part of it.


    But here is link to my original file, without the new code
    http://"https://dl.dropbox.com/u/4380042/Udkast%20til%20dokumentation%20for%20toldpapirer%203.xlsm"


    https://dl.dropbox.com/u/4380042/Udk...pirer%203.xlsm

  • 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!