Hello,
In an Excel sheet I have texts with special format (to insert later in a word document, I use the Excel sheet as a database).
If I copy/paste the cell I keep the format but I need to use a formula to select in each case which text to use (I use a Xlookup) and If I do so, I lose the format.
I tried to make a VBA function to copy with format and mix the function with the xlookup to bring back the selected text wit format.
First attempt:
In an Excel cell I type "=Copy_with_Format(", I select the cell I want to copy and ")"...
It works but copy without the format (like the formula "=").
Then I tried to use ".PasteSpecial":
The only result I obtain is "False"...
Does anyone have an idea to make this function running?
Thank you in advance,
THC (on Office 365)
In an Excel sheet I have texts with special format (to insert later in a word document, I use the Excel sheet as a database).
If I copy/paste the cell I keep the format but I need to use a formula to select in each case which text to use (I use a Xlookup) and If I do so, I lose the format.
I tried to make a VBA function to copy with format and mix the function with the xlookup to bring back the selected text wit format.
First attempt:
VBA Code:
Public Function Copy_with_Format(copiedCell As Range) As String
Copy_with_Format = copiedCell.Value
End Function
It works but copy without the format (like the formula "=").
Then I tried to use ".PasteSpecial":
VBA Code:
Public Function Copy_with_Format(ByVal copiedCell As Range) As String
copiedCell.Copy
Copy_with_Format = copiedCell.PasteSpecial(xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False)
Copy_with_Format = copiedCell.PasteSpecial(xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False)
End Function
Does anyone have an idea to make this function running?
Thank you in advance,
THC (on Office 365)