Copy Named Range Chosen From Drop-Down & Paste To Last Row

  • I am a trainee dermatologist. We undertake allergy patch tests. There is a long list of different patch tests which are selected based on the patients history. I have put each of the types of patch testing on a master sheet. What I would like to be able to do is to have a control button next to each set, and when clicked would add that particular set to a "new patient" worksheet tab. And with every set having its own button, more than one set could be added to a new sheet. In the new patient worksheet id like the sets added with a single row gap between them.
    I had tried, and managed to get a single series to work, but then it wouldnt allow me to add the next set, saying that sheet already exists. Ideally finally, id like there to be some way, or message to make sure after printing the new patient worksheet gets deleted.
    I hope that all makes sense ! Even if I had a code for a single button that added to a master sheet at the next available row +1 I think I could manipulate the code to suit.
    Thanks
    Grant

  • Re: Multisheet Copy Multiple Rows


    Give the attached a try. It is only a rough start to get you pointed in a direction.
    Named Ranges are used for the "sets" and a cell with Data Validation with the list option is used as a selector cell to choose which set to copy.


    The Select Case method is used to test which set is selected for copying.
    A Forms button is used, with macro assigned, to call the macro.
    There is also button with code assigned to print the sheet and clear it.


    This is not "robust" since there is no error checking or tests to see if you are copying duplicate data. There is likely a better approach than Select Case if you have a lot of "sets" to copy.

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Great ! Thats along the lines of what i was thinking. If possible, what i would like to do , is have a button next to each of the sets and when you click on that button the data copies and pastes to the "new patient" worksheet, and then the next would copy and paste with a space row in between. Even if I had a suitable code for one or two ( I could modify for the rest of the sets...as there is quite a few !) Attached is the master list with non functioning buttons as examples. The final button would be the print and delete button as before.
    I am very grateful for your prompt reply
    Thanks
    Grant

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Try the attached and see if this doesn't get you started on an alternative solution; it just hides the rows you don't want printed, prints (previews just for now), and unhides them again.
    I've added a userform and a listbox, this code behind the userform:

    Code
    Private Sub CommandButton1_Click()
    UserForm1.Hide
    End Sub

    this code behind the Print button on the sheet:

    Code
    Private Sub CommandButton1_Click()
    blah
    End Sub

    and this code in a standard module:

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    P45cal - that has worked a treat ! Thanks so much.
    The only slight niggle that I could easily live with, is whether it would be possible that none of the "sets" get split by a page break and would get forced onto a new page. Have a look at the attched which I have adapted slightly. Depending on which sets the user requests , sometimes tehy are quite long, but ideally I would like them appear all on the one sheet. See what you think
    Cheers !

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Oh no , Ive just tried it again and its not working correctly. It doesnt seem to print preview the selected items from the userform, it is print previewing some items but in a random way.
    I did try to rename the userform, perhaps that has affected things. Please have a look, as otherwise it was going great !
    Grant

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Yes, I saw the effect your changing the userform name did - corrected in the attached. There were also several minor errors, you had leg ulcers in twice on the sheet (each header has to be unique), you misspelt one of them in the code, all corrected.


    Page breaks; instead of print preview I've moved to just leaving the sheet in page break preview mode when it's finished. I've abandoned putting all rows back to visible at the end - you don't need to see them at all anyway, and I moved the button so that it can never be hidden - it doesn't matter too much where it is since it's not printed.


    So now, when you've chosen what you want printed and the macro does its stuff, working from top to bottom, you manually drag the page breaks which come in the middle of a table upwards, to line up with the top of that table. Then Print or Print Preview manually. Depending on how many of these you have to do, it may not be worth automating this.
    You can leave the sheet as it is (you don't even have to savethe file).
    Be patient, it's quite slow.
    I'm not sure about the colours..

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Youre a genius ! That works perfectly. The colours werent my choice...honest.
    I did quite like to see the master list from the outset...could that be reinstated ?
    Otherwise its great. I will no doubt ned to use it in action to see how things go.
    Cheers.
    Grant

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    Infact, just as I try it....its perfect as it is. So I would aim to leave as is. If I ever had to edit any entries or add a new series...would that be straight forward ?

  • Re: Copy Named Range Chosen From Drop-Down & Paste To Last Row


    right click on the Master sheet's tab and choose 'View Code'. When the vbe shows up paste this into it:

    Code
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Cells.EntireRow.Hidden = False
    End Sub

    close the vbe and when you doubleclick the sheet all the rows will be unhidden.


    ..or just click the button and check all the checkboxes.

Participate now!

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