VBA: Copy columns from sheet to another and keep the formatting

lunatu

Board Regular
Joined
Feb 5, 2021
Messages
77
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Hi,

Im having a macro which is copying specific columns from sheet2 to sheet1. I have some conditional formatting in sheet1 and I would like to have that to the copied columns aswell. Currently my macro is keeping the formatting from sheet2. Any ideas how to fix this?

Code Im using:
VBA Code:
Sub CopyCell()

Application.ScreenUpdating = False

Worksheets("Sheet1").Unprotect

Application.ScreenUpdating = False

Dim LR As Long, i As Long

With Sheets("Sheet2")

LR = .Range("H" & Rows.Count).End(xlUp).Row

For i = 1 To LR

If .Range("H" & i).Value = "SalesPerson1" And .Range("J" & i).Value = "Negotiate" Then

dlr = Sheets("Sheet1").Cells(Rows.Count, "D").End(xlUp).Row + 1

.Range("A" & i).Resize(1, 9).Copy Destination:=Sheets("Sheet1").Range("D" & dlr)

Sheets("Sheet1").Range("C" & dlr) = Date

End If

Next i

End With

Worksheets("Sheet1").Range("C:T").Locked = False

Worksheets("Sheet1").Protect

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
can you give us a dummy record with the same formatting as the actual record and see if we can help you, kindly use xl2bb (y)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

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