VBA - Search sheet based on criteria, copy column, paste in the next colmun to right

  • Hi,


    I'm currently relatively new to the VBA arena and am trying to solve a time consuming task via the help of VBA in Excel.


    I have attached an very basic example of the excel data and layout I'm working with. This is what I need the code to do:


    1. Search for the string in Sheet 1 (cell A2) and find it in Sheet 2.
    2. Copy the entire column of the found column.
    3. Paste the formulas/data in the column next to the found column.


    Do you think there is anyone how could potentially help me with this problem?


    Thanks in advance for the help.


    Kind regards,


    05125668

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    first the date is not in A2 but in B1 (typo error)
    I have a doubt with the formula as it is written now in L2,L3 etc
    in column L the sum is L2: L9,L3:L9 etc
    what should be the formula in M2, M3, M4 etc.
    reply.

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Hi Venkat1926,


    Thanks for your reply. Yes you're correct the date is in B1, apologises for this.


    In terms of the formula in column M, I just created dummy formulas as I just need to this is work in principal and then I can modify this to work in document I'm currently working in. You can put whatever formula you like in column M, I just need the vba code to copy the formulas and paste them in the next blank column to the right (i.e, column N).


    Unfortunately I can't send through the master as the document is rather large in size and also has confidential information in it.


    Please let me know if you need any further information and thanks again.


    Kind regards,

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    you need NOT send the whole sheet. copy a small extract in another file and send the file (there is provision in this newsgroup to send small files). also explain what you want clearly. preferably how the result should look perhaps in another sheet will be useful to understand the problem,

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Hi,<BR><BR>hopefully this should be of more help.&nbsp; I have put in a bit more information and have also put in an instructions tab to details what I need the vba code to do.&nbsp; Please let me know if you need any further information.<BR><BR>Many thanks in advance.

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    As I do not know the implication of this arithmetical operations I am not able to test it completely


    try this macro and give your feedback
    SAVE YOUR ORIGINAL FILE SAFELY SOMEWHERE FOR RETRIEVAL IF SOMETHING GOES WRONG
    MAKE A FEW EXPERIMENT BY CHANGING DATA IN DASHBOARD AND ALSO IN BUSINESS SHEET
    TILL YOU ARE SATISFIED THAT THE MACRO DOES WHAT YOU WANT.


  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Hi venkat1926,


    Thanks very much for taking the time to do this. The code did works as I requested and I made some additions to create a fail safe to prevent the formulas from being deleted.


    I just need one last thing to be performed in the code and for the next months header to be found in "Business Unit XX" and this columns and all columns to the right of this to be hidden.


    I have put code below that will find the next month header but I just need the vba code that will hide that column and all others to the right


  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Sorry here is the modified workbook.


    I also forgot to mention that I will need to run the same code for multiple business units.


    Is there anyway to call the code but change the worksheet name of the business unit worksheet? I have added this to the excel document to show what I mean.


    Please let me know if you need any more information.


    Kind regards,

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Code
    "nmonth -.Range("B3").Value"


    typo error
    change it

    Code
    nmonth =.Range("B3").Value

    (change minus sign to equal to sign)


    "

    Code
    If cfind.Offset(2, 0).Value <> "" Then

    "
    should it be

    Code
    If cfind.Offset(0,2).Value <> "" Then

    (though not clear why this is ncessary)


    before end if and the two end with(s) this statement


    Code
    range(cfind.offset(0,2),cfind.end(xltoright)).entirecolumn.hidden=false


    for using it on any sheet
    replace this line

    Code
    With Worksheets("Business Unit XX")


    with


    d

    Code
    im ws as string

    (this goes in the beginning along with other dims
    for replacement of above line (with worksheets........) these two lines


    Code
    ws=inputbox("type the name of the sheet")
    with worksheets(ws)


    hope you can modify

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    Hi venkat1926,


    Thanks sooo much for your help, I have managed to make the modifications you suggested and it now works a treat. Thanks for having the patience with me as I know my initial requirements weren't clear.


    Please see below for the final code:



    Thanks very much again


    Kind regards,


    05125668

  • Re: VBA - Search sheet based on criteria, copy column, paste in the next colmun to ri


    good. you did it on your own with some little help. wish you best of everything

Participate now!

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