Move a whole row to a new worksheet row based on entry in one cell but not if input entry is in another cell

RID

New Member
Joined
Dec 17, 2009
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Good afternoon, is there a formula that can be used to do the following, I have a worksheet for reviews that we have internal comments for our own use and responses to customer. I have a sneaky feeling that this will probably need some sort of VBA code but thought I would ask the question if can be done by formula first off. Currently we have that what ever is in column F on worksheet 1 is transferred into worksheet but as you can see when there is no entry in column F it still transfers the row because we have someting in column D.

If there is input in Column F 'Response to Customer' cells I would like to transfer the whole row onto a new worksheet which is the bottom screenshot, but if there is an input in Colum D 'Internal Comment' then the row is not transfered to the second worksheet.

Any pointers would be appreciated if I need to start looking at VBA where should I be looking at and is there specific tutorials that can get me going?

1614689674499.png



1614689851723.png
 
Replace the current macro with the code below. When you enter data in column F and press the RETURN key, the data will be copied to Doc 2. If you delete any existing data in column F, the corresponding data in Doc 2 will be cleared.
VBA Code:
Dim oldVal As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 6 Then Exit Sub
    oldVal = Range("A" & Target.Row).Value
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 6 Then Exit Sub
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, lRow As Long, fnd As Range
    Set desWS = Sheets("Doc 2")
    lRow = desWS.Range("B" & Rows.Count).End(xlUp).Row
    If Target <> "" Then
        If Target.Offset(, -2) = "" Then
            With desWS
                If lRow = 2 Then
                    .Range("A" & lRow + 1).Resize(, 3).Value = Range("A" & Target.Row).Resize(, 3).Value
                    .Range("F" & lRow + 1).Value = Range("F" & Target.Row).Value
                Else
                    lRow = lRow + 7
                    .Range("A" & lRow).Resize(, 3).Value = Range("A" & Target.Row).Resize(, 3).Value
                    .Range("F" & lRow).Value = Range("F" & Target.Row).Value
                End If
            End With
        End If
    Else
        Set fnd = desWS.Range("A:A").Find(oldVal, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            desWS.Rows(fnd.Row).ClearContents
        End If
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Nope that didnt work mummps my input into column F no longer copies
 
Upvote 0
Also found another flaw, if I make a mistake in one of the column F cells and go back to sort it, instead of changing that cell with the new content it pastes the new row at the next available one and keeps the one with the original mistake in it
 
Upvote 0
Try:
VBA Code:
Dim oldVal As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 6 Then Exit Sub
    oldVal = Range("A" & Target.Row).Value
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 6 Then Exit Sub
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, lRow As Long, fnd As Range
    Set desWS = Sheets("Doc 2")
    lRow = desWS.Range("B" & Rows.Count).End(xlUp).Row
    If Target <> "" Then
        Set fnd = desWS.Range("A:A").Find(oldVal, LookIn:=xlValues, lookat:=xlWhole)
        If fnd Is Nothing Then
            If Target.Offset(, -2) = "" Then
                With desWS
                    If lRow = 2 Then
                        .Range("A" & lRow + 1).Resize(, 3).Value = Range("A" & Target.Row).Resize(, 3).Value
                        .Range("F" & lRow + 1).Value = Range("F" & Target.Row).Value
                    Else
                        lRow = lRow + 7
                        .Range("A" & lRow).Resize(, 3).Value = Range("A" & Target.Row).Resize(, 3).Value
                        .Range("F" & lRow).Value = Range("F" & Target.Row).Value
                    End If
                End With
            End If
        Else
            With desWS
                .Range("A" & fnd.Row).Resize(, 3).Value = Range("A" & Target.Row).Resize(, 3).Value
                .Range("F" & fnd.Row).Value = Range("F" & Target.Row).Value
            End With
        End If
    Else
        Set fnd = desWS.Range("A:A").Find(oldVal, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            desWS.Rows(fnd.Row).ClearContents
        End If
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I tested the code on the file you posted and it works properly. Can you upload a copy of the workbook that is not working for you?
 
Upvote 0
Just to note I changed the file name on the tab to client 1, so where it references Doc 2 in the code I swapped it out with Client 1
 
Upvote 0
It looks like you want the code to work on all the "Doc" sheets and copy to the appropriate "Client" sheet. Is this correct?
 
Upvote 0
Yes if that can be done it would be great
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top