annadinesh
Board Regular
- Joined
- Mar 1, 2017
- Messages
- 105
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim rng As Range
'~~> Change to relevant sheet
Set ws = Sheet1
With ws
If Date - CDate(.Range("G6").Value2) > 730 Then
Set rng = .Range("C23")
Else
Set rng = .Range("C24")
End If
rng.Copy
With .Range("A2")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
End With
End Sub
where to put the code in module or same worksheetYou cannot copy formats using an excel formula. You need to use VBA for that. is this what you are trying?
VBA Code:Option Explicit Sub Sample() Dim ws As Worksheet Dim rng As Range '~~> Change to relevant sheet Set ws = Sheet1 With ws If Date - CDate(.Range("G6").Value2) > 730 Then Set rng = .Range("C23") Else Set rng = .Range("C24") End If rng.Copy With .Range("A2") .PasteSpecial Paste:=xlPasteValues .PasteSpecial Paste:=xlPasteFormats End With End With End Sub
where to put the code in module or same worksheet
Thanks its working , But Same format is not copying, Like A line is in BOLD and A line is in RED Colour, and G6 is merge cell of 4 cells, the value is copying in all 4 cellsIn a module.
In a module.
Thanks its working , But Same format is not copying, Like A line is in BOLD and A line is in RED Colour, and G6 is merge cell of 4 cells, the value is copying in all 4 cells
Please help
the data is copying from C23 & C24 , but please check the attached image file i have already attached there ia paragraph in which a line is in BOLD and a Line is in RED Colour, is there any formula to copy the same format to another as per your code, your code is working fine, and A2 is a merged cell of 6 cells from A2 to F2, the value of C23 is copying to all 6 cells instead of A2 OnlyDid you change anything in the code because I am not copying G6.
the data is copying from C23 & C24 , but please check the attached image file i have already attached there ia paragraph in which a line is in BOLD and a Line is in RED Colour, is there any formula to copy the same format to another as per your code, your code is working fine, and A2 is a merged cell of 6 cells from A2 to F2, the value of C23 is copying to all 6 cells instead of A2 Only