Avatar of Amy kanne
Amy kanne
 asked on

Move entire row to another workbook based on cell value

i am trying to create a VBA to move a row from sheet1 to sheet2 based on whether there is data in Column k or not but am having difficulty as i am new to excel and still learning.
CDI-Escalation-NO-ResponseTracking-.xlsx
VBAMicrosoft ApplicationsMicrosoft OfficeMicrosoft Excel

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Subodh Tiwari (Neeraj)

Hi Amy,

The detail you provided is not sufficient to derive a solution. Please elaborate it a bit more and upload a sample workbook (without any sensitive data) along with the desired output mocked up manually on another sheet, you may name that sheet as Desired.
Amy kanne

ASKER
i have attached the workbook
Subodh Tiwari (Neeraj)

Sorry! At least I am not sure what are you trying to achieve here unless you clearly describe it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Amy kanne

ASKER
i want to be able to move  an entire row from sheet 1 to sheet 2 once a response is selected from the drop down in column K.  So, if column k is blank then the row stays on sheet 1 and if column k is filled in the row moves to sheet 2.
Subodh Tiwari (Neeraj)

The column K is not the last column on the Sheet1 but it is column L.
If you want the entire row to be moved onto the Sheet2 once you select an option in column K, how would you fill the column L then?
Or would you select an option in column K after filling the column L?

The above query makes sense if you need a Change Event Code for Sheet1 so that once you select the value in column K, the entire row would be moved to the Sheet2.

But if you want a button to manually run the code by hitting the button to move all the rows where column K has value in it, that will not be an issue.

What would you prefer then?

Also, on Sheet2, there are already some tables so where exactly you want the rows from Sheet1 to go?
Amy kanne

ASKER
column L will be filled in periodically during the process so once column K is filled in it needs to go to sheet 2 regardless of whether there is data in column L or not.  on sheet 2 i had moved the headers from sheet 1 into sheet 2 so i would want the rows from sheet 1 to go underneath those headers
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Subodh Tiwari (Neeraj)

You may try something like this...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Dim dws As Worksheet
Dim dlr As Long, r As Long
Set dws = Sheets("Sheet2")
On Error GoTo Skip
If Target.Column = 11 And Target.Row > 3 Then
    If Target <> "" Then
        Application.EnableEvents = False
        r = Target.Row
        If dws.Range("A9").Value = "" Then
            dlr = 9
        Else
            dlr = dws.Cells(Rows.Count, 1).End(xlUp).Row + 1
        End If
        Range("A" & r & ":L" & r).Copy
        dws.Range("A" & dlr).PasteSpecial xlPasteValues
        dws.Range("A" & dlr).PasteSpecial xlPasteFormats
        Rows(r).Delete
    End If
End If
Skip:
Application.EnableEvents = True
End Sub

Open in new window

CDI-Escalation-NO-ResponseTracking-.xlsm
Amy kanne

ASKER
this is moving the row but when i enter new data that i would like to work in the same fashion but it replaces what is on sheet 2 instead of adding another row to sheet 2.  i have attached an updated file
CDI-Escalation-NO-ResponseTracking-.xlsm
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Amy kanne

ASKER
this works perfectly. thank you so much for all of your help
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Subodh Tiwari (Neeraj)

You're welcome Amy! Glad it worked as desired.