VBA find function when not found

  • Hi, I have one sheet in my file named "G2N" which has column headers in a fixed order and i want to populate the rows under those columns with data from another sheet which i is called "BDOG2N".


    The column headers are not in the same order in the different sheets and "BDOG2N" might have column headers that are not in the "G2N" sheet and vice versa.


    I have tried to do this via VBA with the find function and running into a problem when I have a header in the "BDOG2N" which doesnt exist in the "G2N" sheet. If this happens, then i want to print/write the column header name somewhere so I can investigate this column manually once makro has completed.


    Thank you


  • Welcome to Ozgrid


    Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags

    Note: no apostrophe in the tags, just used for demonstration here.

    ['code]


    your code goes between these tags


    ['/code]


    Or, just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

  • Possibly...

    If I've been helpful, let me know. If I haven't, let me know that too.

  • Check it out.


  • Correction...

    If I've been helpful, let me know. If I haven't, let me know that too.

  • I have tried with the codes provided above as stand alone codes. (Possibly they were partial codes i should implement in my own original?)

    With the code from Dangelor i run into an error on line item 11: "Object variable or with block variable not set"


    With the code from Davesexcel runs well but incase there is one ore more column headers in the "BDOG2N" which doesnt exist in the "G2N" sheet. I want to print/write the column header name somewhere so I can investigate these column(s) manually once makro has completed. This can be for example in a new work book or similar. Perhaps it is already doing it but i didnt find it? The code was so elegant i dont really understand much of it..!