How can I copy Excel cells with rich text formatting but not the global cell format?

前端 未结 2 1071

Using VBA, I\'m copying the value of one cell to another:

Dim s As Range
Dim d As Range
Set s = Range(\"A1\")
Set d = Range(\"B2\")
d.Value = s.Value
         


        
相关标签:
2条回答
  • 2021-01-18 07:09

    I've just made some test and I'm bit surprised with results which could be solution for you or just a tip to explore it more.

    Imagine we have this situation at the beginning:

    enter image description here

    If you run this simple code:...

    Sub PossibleSolution()
    
        Range("A1").Copy     'full formatted cell
        Range("A3").PasteSpecial xlPasteAll
        Range("A2").Copy     'clear format cell
        Range("A3").PasteSpecial xlPasteFormats
    
    End Sub
    

    ...you will get the following result:

    enter image description here

    0 讨论(0)
  • 2021-01-18 07:35

    Range.Value has an optional RangeValueDataType parameter (11 is xlRangeValueXMLSpreadsheet):

     Range("B2").Value(11) = Range("A1").Value(11) 
    
    0 讨论(0)
提交回复
热议问题