Hi All,
I have a piece of code which works well, but I am unsure how to amend it...
The code transfers data based on a criteria to the relevant worksheet. I need to amend it so that it doesn't remove any of the formatting that is present on the entire destination sheet ("RM DOM") and simply pastes the values. I have conditional formatting, formula and data validation from columns AB to AS which I need to keep. At the minute this code removes everything each time it is run. Is this possible?
Here's my code:
Thanks, Jo
I have a piece of code which works well, but I am unsure how to amend it...
The code transfers data based on a criteria to the relevant worksheet. I need to amend it so that it doesn't remove any of the formatting that is present on the entire destination sheet ("RM DOM") and simply pastes the values. I have conditional formatting, formula and data validation from columns AB to AS which I need to keep. At the minute this code removes everything each time it is run. Is this possible?
Here's my code:
Code:
Private Sub RM_DOM_Click()
Sheets("RM DOM").Unprotect "Minors"
Dim x As Long
Dim LR As Long
Dim LC As Long
Dim msg As String
Dim arr() As Variant
Dim w As Worksheet: Set w = Sheets("Minor Sales")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
With w
LC = .Range("AA1").Column '27
LR = .Cells(.Rows.Count, 2).End(xlUp).Row
For x = 3 To LR
msg = LCase$(.Cells(x, 2).Value & .Cells(x, 19).Value)
If msg = "domyes" Then
arr = .Cells(x, 1).Resize(, LC).Value
Sheets("RM " & .Cells(x, 2).Value).Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, LC).Value = arr
End If
Next x
End With
Set w = Nothing
msg = vbNullString
Erase arr
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Sheets("RM DOM").Visible = True
Sheets("RM DOM").Range("A:AS").RemoveDuplicates Columns:=Array(3)
Sheets("RM DOM").Range("$A$2:$AS$9970").AutoFilter Field:=27
Sheets("RM DOM").Range("$A$2:$AS$9970").AutoFilter Field:=27, Criteria1:="<>"
Sheets("RM DOM").Protect "Minors", True, True
Sheets("RM DOM").Select
End Sub
Thanks, Jo