Hi all, new to VBA so please be gentle.
I have created my first piece of coding and need to amend it slightly but not sure how.
Basically I am wanting to copy data from sheet 1 (Sales) and paste to either sheet 2 (RM DOM) or sheet 3 (RM IND) based on two IF statements.
If column B in sheet "Sales" = "DOM" & column S = "Yes" then: paste to the next free row in sheet "RM DOM"
If column B in sheet "Sales" = "IND" & column S = "Yes" then: paste to the next free row in sheet "RM IND"
There are 2 header rows in each sheet and the data is to be posted from row 3 down.
I have managed to get this to work to copy the entire row, however I need to amend the code to copy and paste a range ("A:AA") so that additional data can be added to columns in the destination sheets.
On top of this I have added a line to remove duplicates based on a unique sales reference number which will be present in column C.
Any help would be appreciated as I have exhausted Google to solve this. TIA
Here's the code I have so far:
Sub CopyVal()
a = Worksheets("Minor Sales").Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To a
If Worksheets("Minor Sales").Cells(i, 2).Value = "DOM" Then
Worksheets("Minor Sales").Cells(i, 19).Value = "Yes"
Worksheets("Minor Sales").Rows(i).Copy
Worksheets("RM DOM").Activate
b = Worksheets("RM DOM").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("RM DOM").Cells(b + 1, 1).Select
Worksheets("RM DOM").Paste
End If
Application.CutCopyMode = False
Worksheets("RM DOM").Range("A:AS").RemoveDuplicates Columns:=Array(3)
Next
a = Worksheets("Minor Sales").Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To a
If Worksheets("Minor Sales").Cells(i, 2).Value = "IND" Then
Worksheets("Minor Sales").Cells(i, 19).Value = "Yes"
Worksheets("Minor Sales").Rows(i).Copy
Worksheets("RM IND").Activate
b = Worksheets("RM IND").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("RM IND").Cells(b + 1, 1).Select
Worksheets("RM IND").Paste
End If
Application.CutCopyMode = False
Worksheets("RM IND").Range("A:AS").RemoveDuplicates Columns:=Array(3)
Next
End Sub
I have created my first piece of coding and need to amend it slightly but not sure how.
Basically I am wanting to copy data from sheet 1 (Sales) and paste to either sheet 2 (RM DOM) or sheet 3 (RM IND) based on two IF statements.
If column B in sheet "Sales" = "DOM" & column S = "Yes" then: paste to the next free row in sheet "RM DOM"
If column B in sheet "Sales" = "IND" & column S = "Yes" then: paste to the next free row in sheet "RM IND"
There are 2 header rows in each sheet and the data is to be posted from row 3 down.
I have managed to get this to work to copy the entire row, however I need to amend the code to copy and paste a range ("A:AA") so that additional data can be added to columns in the destination sheets.
On top of this I have added a line to remove duplicates based on a unique sales reference number which will be present in column C.
Any help would be appreciated as I have exhausted Google to solve this. TIA
Here's the code I have so far:
Sub CopyVal()
a = Worksheets("Minor Sales").Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To a
If Worksheets("Minor Sales").Cells(i, 2).Value = "DOM" Then
Worksheets("Minor Sales").Cells(i, 19).Value = "Yes"
Worksheets("Minor Sales").Rows(i).Copy
Worksheets("RM DOM").Activate
b = Worksheets("RM DOM").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("RM DOM").Cells(b + 1, 1).Select
Worksheets("RM DOM").Paste
End If
Application.CutCopyMode = False
Worksheets("RM DOM").Range("A:AS").RemoveDuplicates Columns:=Array(3)
Next
a = Worksheets("Minor Sales").Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To a
If Worksheets("Minor Sales").Cells(i, 2).Value = "IND" Then
Worksheets("Minor Sales").Cells(i, 19).Value = "Yes"
Worksheets("Minor Sales").Rows(i).Copy
Worksheets("RM IND").Activate
b = Worksheets("RM IND").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("RM IND").Cells(b + 1, 1).Select
Worksheets("RM IND").Paste
End If
Application.CutCopyMode = False
Worksheets("RM IND").Range("A:AS").RemoveDuplicates Columns:=Array(3)
Next
End Sub