For all the copy paste special actions, I would like to paste the conditional format…
- User
For all the copy paste special actions, I would like to paste the conditional format from source to target Can you help me make sure that the code below does this
Sub CopyFormulasAndCalculate() Dim wsSource As Worksheet, wsTarget As Worksheet Dim rngSource As Range, rngTarget As Range, rngDelete As Range, cell As Range ' Set the source and target worksheets Set wsTarget = ThisWorkbook.Worksheets("SsBOOKonly") Set wsSource = ThisWorkbook.Worksheets("BOOKING") ' Clear contents of target sheet wsTarget.Cells.Clear ' Copy values and formats from source to target Set rngSource = wsSource.UsedRange Set rngTarget = wsTarget.Range("A1").Resize(rngSource.Rows.Count, rngSource.Columns.Count) rngSource.Copy rngTarget.PasteSpecial xlPasteValuesAndNumberFormats ' Delete rows with ‘School Bookin' in column B Set rngDelete = Nothing ' Reset delete range For Each cell In wsTarget.Range("B:B") If cell.Value = "School Booking" Then If rngDelete Is Nothing Then Set rngDelete = cell.EntireRow Else Set rngDelete = Union(rngDelete, cell.EntireRow) End If End If Next cell If Not rngDelete Is Nothing Then rngDelete.Delete ' Copy formulas from source to target (columns H and I) wsSource.Range("H:I").Copy wsTarget.Range("H:I").PasteSpecial xlPasteFormulasAndNumberFormats Call Module2.CalculateSsBooking End Sub
- Assistant
The code you provided is almost correct. However, there is a small mistake in the line where you copy the conditional format from the source to the target. Instead of using
xlPasteValuesAndNumberFormats, you should usexlPasteFormatsto copy only the conditional format.Here is the corrected code:
Sub CopyFormulasAndCalculate() Dim wsSource As Worksheet, wsTarget As Worksheet Dim rngSource As Range, rngTarget As Range, rngDelete As Range, cell As Range
code - User
In this module, I am trying to copy the conditional formatting from the Source to the Target. It is not doing what I want. Can you please correct it: Sub TransferFormat() Dim wsSource As Worksheet, wsTarget As Worksheet Dim rngSource As Range, rngTarget As Range, rngDelete As Range, cell As Range ' Set the source and target worksheets Set wsTarget = ThisWorkbook.Worksheets("SsBOOKonly") Set wsSource = ThisWorkbook.Worksheets("BOOKING") ' Copy conditional format from source to target wsSource.Copy wsTarget.PasteSpecial xlPasteFormats ' Calculate the target sheet wsTarget.Calculate MsgBox "Check SsBOOKonly for info on days not on site" End Sub
- Assistant
In your code, you are trying to copy the entire source worksheet to the target worksheet using the
Copymethod. This will copy not just the conditional formatting but also all the other elements of the source worksheet, such as values, formulas, and other formatting.To copy only the conditional formatting from the source to the target, you can use the
Copymethod of theRangeobject. Here is the corrected code:vba