Find Value And Copy Related Values

  • Right now I am building a Macro which can be found underneath. The red code is not working right now and I am looking for alternatives to solve this error but until now I haven't found none.


    Basically, I am looking for a correct code to copy files from a sheet to another sheet with a find macro.


  • Re: Find Value And Copy Related Values


    Quote


    The red code is not working right now


    Specifically - what isnt working - what is the error? What is not happening?

    Quote


    Basically, I am looking for a correct code to copy files from a sheet to another sheet with a find macro.


    The code you showed in the macro does not copy files, it copies the contents of cells from row 4 column 1, 3 and 5 of sheet "Voorraadscherm" to row "X" on sheet "Voorraadscherm" (i.e. the same sheet).


    Row X is 2 rows beyond the last row that contains data in Column A on Sheet "Voorraadverloop".


    Other than that, I dont know what you are doing / what you expect to happen / how you expect your code to achieve that / what is wrong with your code.


    Take care,
    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Find Value And Copy Related Values


    The function of this macro is to find cell "A21" from the sheet "voorraadscherm" in the sheet "Voorraadverloop". When this cell is found, the macro should copy the contents from the cells "A21, C21 and E21" from the sheet "voorraadscherm" to the first available row in the sheet "Voorraadverloop". I've made a little screenshot of the purpose of the macro.


    [Blocked Image: http://i25.tinypic.com/2mz2bq.jpg]


    The code will be something like this then, but it still doesn't work.



    The error I get is nr. 438: The property or method isn't supported by this object. The error emerges when it reaches this piece of code: Lr = Worksheets("Voorraadverloop").ActiveCell.End(xlDown).Row + 2


    I hope I made myself a little bit more clear. Since English isn't my native language, it's a bit harder for me to explain what I try to do. If you still got some questions, please ask them, I will be glad to anwser them if that will solve my problem :)


    Regards,


    Barbaar

  • Re: Find Value And Copy Related Values


    Hi


    I think if you replace


    Code
    Lr = Worksheets("Voorraadverloop").ActiveCell.End(xlDown).Row + 2


    with


    Code
    Lr = ActiveCell.End(xlDown).Row + 2


    that will give you the value you need for Lr, assuming you are running the macro with Voorraadverloop as the active sheet.


    HTH


    Robert

  • Re: Find Value And Copy Related Values


    Thnx, that's almost it! :grin:


    There is only one more thing needed to solve this problem.


    If productnummer (cell A21 in sheet "Voorraadscherm") is 456, the macro should copy the contents of Cells from row 4 column 1, 3 and 5 of sheet "Voorraadscherm" to the designated area in the sheet "voorraadverloop".


    I have tried to solve this before, but I keep failing on solving this problem. I hope you can help me with this part too. If so, you really made my day/week/year!


    Thnx for all the support so far guys! Much appreciated!

  • Re: Find Value And Copy Related Values


    Hi
    try replacing this sequence

    Code
    .Cells(Lr, 1) = Sheets("Voorraadscherm").Cells(21, 1) 
                       .Cells(Lr, 3) = Sheets("Voorraadscherm").Cells(21, 3) 
                        .Cells(Lr, 5) = Sheets("Voorraadscherm").Cells(21, 5)


    with this


    Code
    dim SourceCell as Range,TargetCell as Range
    Set TargetCell = Sheets("Voorraadverloop").Range("A" & LR)
    set SourceCell = Sheets("Voorraadscherm").Range("A21")
    SourceCell .Copy Destination:= TargetCell
    SourceCell.Offset(0,2) .Copy Destination:= TargetCell.Offset(0,2)
    SourceCell.Offset(0,4) .Copy Destination:= TargetCell.Offset(0,4)


    I am not certain that the construct .Cells(n,n) is valid. If you are defining a cell within a declared range, the form .Cells(n) is usually OK


    HTH


    Robert

  • Re: Find Value And Copy Related Values


    I received another solution for this problem. This is the following code:



    I now want to use this code for multiple cells. They are shown on the image I provided some posts above. It's the table within the range of A4-I13. Any of you guys know how to bend this macro in the correct way for this purpose? I tried too, but I failed :(


    The code I have right now is this:


    thnx in advance

Participate now!

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