Drop down

Closed
Moana - Feb 9, 2023 at 03:04 PM
vcoolio Posts 1404 Registration date Thursday July 24, 2014 Status Moderator Last seen September 15, 2023 - Feb 10, 2023 at 03:55 AM

Hello,

I have a workbook with one main sheet and lots of rows to be filled. There is one column with a drop down with 3 selection.

How can I copy the entire row, automaticly to antoner sheet based on the drop down selection? 

So I have in the drop down menu in one column

crewed

bareboat

Du

and then I have the same sheets:

crewed

bareboar

Du

ans when I choose Crewed in the main sheet, I want that row to automaticly be copied in the sheet Crewed.

Thank you


iPhone / Safari 16.1

2 responses

vcoolio Posts 1404 Registration date Thursday July 24, 2014 Status Moderator Last seen September 15, 2023 259
Feb 9, 2023 at 06:14 PM

Hello Moana,

Assuming that your drop downs are in Column A, try the following code placed into the worksheet module:-

Private Sub Worksheet_Change(ByVal Target As Range)

    If Intersect(Target, Columns(1)) Is Nothing Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Value = vbNullString Then Exit Sub
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Target.EntireRow.Copy Sheets(Target.Value).Range("A" & Rows.Count).End(3)(2)
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub

The code is a Worksheet_Change event code and will work instantly once a drop down selection is made.

To implement this code:-

- Right click on the main input sheet tab.

- Select "View Code" from the menu that appears.

- In the big white code field that then appears, paste the above code.

If you need to delete the relevant row of data from the main input sheet after the data transfer is completed, place this line of code:-

Target.EntireRow.Delete

directly after this line of code:-

Target.EntireRow.Copy Sheets(Target.Value).Range("A" & Rows.Count).End(3)(2)

I hope that this helps.

Cheerio,

vcoolio.

0

Dear Vcoolio,

I am not able to add the code?

Can you please explain where to input the code? I don't have view code?

Best regards,

0
vcoolio Posts 1404 Registration date Thursday July 24, 2014 Status Moderator Last seen September 15, 2023 259
Feb 10, 2023 at 03:55 AM

Hello Moana,

Every version of Excel has a "View Code" option in the context menu of any worksheet. Did you follow the instructions in post #1? Did you right click on the main sheet tab?

If you are still having problems, upload a sample of your workbook to a file sharing site such as WeTransfer or Drop Box and then post the link to your file back here. This way, we can have a look at what might not be working.

Cheerio,

vcoolio.

0