Combine code to move rows based on cell value

edwardl96

New Member
Joined
May 15, 2014
Messages
23
Hi all,

I am trying to combine sections of code to achieve the following:

I have three worksheets: “raw data”, “completed” & “quote”.
All workbooks have the exact same layout
The header takes up row 1
Data fills column A-H. H is a status column with a drop down list, here you can select : “raw data”, “completed” & “quote”

What i am trying to achieve: On any worksheet, when the status is changed, the row is automatically sent to the corresponding worksheet.

This is what i have so far, this has been entered in the code for worksheet "raw data", part of the code will work by it’s self as below:

Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheets("raw data") 'Edit sheet name
Set sh3 = Sheets("quote") 'Edit sheet name
lr = sh1.Cells(Rows.Count, 8).End(xlUp).Row
Set rng = sh1.Range("H2:H" & lr)
If Not Intersect(Target, rng) Is Nothing Then
    Application.EnableEvents = False
        If LCase(Target.Value) = "quote" Then
            Range("A" & Target.Row).Resize(1, 8).Copy
            sh3.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues
            Range("A" & Target.Row).EntireRow.Delete
        End If
    Application.EnableEvents = True
End If
Application.CutCopyMode = False
 
End Sub


I have tried to combine multiple sections to achieve my goal ut it hasnt gone very well; this is what I have tried to do to combine the code to:

Code:
Sub MasterMacro()
Call Worksheet_Change
Call Worksheet_Change2
End Sub
Sub Worksheet_Change(ByVal Target As Range)
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheets("raw data") 'Edit sheet name
Set sh3 = Sheets("quote") 'Edit sheet name
lr = sh1.Cells(Rows.Count, 8).End(xlUp).Row
Set rng = sh1.Range("H2:H" & lr)
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
If LCase(Target.Value) = "quote" Then
Range("A" & Target.Row).Resize(1, 8).Copy
sh3.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues
Range("A" & Target.Row).EntireRow.Delete
End If
Application.EnableEvents = True
End If
Application.CutCopyMode = False
End Sub

Sub Worksheet_Change2(ByVal Target As Range)
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheets("raw data") 'Edit sheet name
Set sh2 = Sheets("completed") 'Edit sheet name
lr = sh1.Cells(Rows.Count, 8).End(xlUp).Row
Set rng = sh1.Range("H2:H" & lr)
If Not Intersect(Target, rng) Is Nothing Then
Application.EnableEvents = False
If LCase(Target.Value) = "completed" Then
Range("A" & Target.Row).Resize(1, 8).Copy
sh2.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues
Range("A" & Target.Row).EntireRow.Delete
End If
Application.EnableEvents = True
End If
Application.CutCopyMode = False
End Sub

If anyone can tell me how to combine the code so I can make the workbook do as I want I will be eternally grateful!!!

Thank you very much in advance :)
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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