COPYING A CELL VALUE TO ANOTHER CELL WITH SAME FORMAT WITH FORMULA

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
105
Hi Team

I want to copy cell value of C23 & C24 to A2 based on Date via formula =IF(TODAY()-G6>730,C23,C24)

but the value comes on G6 should as same as in C23 & C24 format.


Please help


Dinesh Saha
9932022569
 

Attachments

  • excel value.jpg
    excel value.jpg
    111.7 KB · Views: 7

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You 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
 
Upvote 0
You 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
 
Upvote 0
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

Did you change anything in the code because I am not copying G6.
 
Upvote 0
Did 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
 
Upvote 0
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

I believe, C23 and C24 is also merged? Else you would not have been able to copy from a single cell to a merged cell using the code that I provided? Would it be possible to see your Excel file so that I can give you a more accurate solution?
 
Upvote 0
Solution
Yess BOSS u r right C23 and C24 are Merged , Copy Problem Solved, But Please help me with the Format of C23 and C24 value
 
Upvote 0

Forum statistics

Threads
1,215,450
Messages
6,124,912
Members
449,195
Latest member
Stevenciu

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