Description: When copying cell formulas using VBA, the normal method is: Worksheets("Sheet1").Range(D4:E6).Copy Worksheets("Sheet2")Range("D4:E6").PasteSpecial Paste:=xlPasteFormats What is copied is whatever range that is selected! To make it work, you must select the range you want to copy: Add this line first: Worksheets("Sheet1").Range(D4:E6).Select Steps to Reproduce: 1. Worksheets("Sheet1").Range(D4:E6).Copy Worksheets("Sheet2")Range("D4:E6").PasteSpecial Paste:=xlPasteFormats 2. Worksheets("Sheet1").Range(D4:E6).Select Worksheets("Sheet1").Range(D4:E6).Copy Worksheets("Sheet2")Range("D4:E6").PasteSpecial Paste:=xlPasteFormats Actual Results: 1. Formatting copied from range that is selected, not the range specified! 2. This solves the problem but isn't the correct way to do format copy Expected Results: See Actual Results Reproducible: Always User Profile Reset: No Additional Info: [Information automatically included from LibreOffice] Version: 6.1.4.1 (x64) Build ID: 25073d18caee244880112e52c4a7e71f6081b3a9 CPU threads: 4; OS: Windows 10.0; UI render: GL; Locale: nb-NO (nb_NO); Calc: CL
https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbarange.cxx?r=892a5cfe#2514 https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/excelvbahelper.cxx?r=892a5cfe#177 https://opengrok.libreoffice.org/xref/core/sc/source/ui/view/viewfun3.cxx?r=6256797d#156 https://opengrok.libreoffice.org/xref/core/sc/source/ui/view/viewfun3.cxx?r=6256797d#185
Please attach test file. Thank you
Created attachment 148284 [details] Workbook with macros This file contains macros that explain the problem. See content for further descriptions
i can confirm the problem: format from selected cell is copied instead of format from source range possible workaround: Worksheets("Sheet1").Range(rSrc).Copy destination:=Worksheets("Sheet2").Range(rDSt) Worksheets("Sheet2").Range(rSrc).ClearContents
Thanks! But the code fails to remove the contents of the copied range. rSrc = "B2:C5" rDst = "E2" Worksheets("Sheet1").Range(rSrc).Copy destination:=Worksheets("Sheet2").Range(rDSt) Worksheets("Sheet2").Range(rDst).ClearContents rDst points to upper left corner in the destination sheet, which is cleared. rScr and rDst are not equal! To make it work, you need to set rDst = "E2:F5" (same size) But anyway, it's close to a solution. This bug cost me a lot of trouble because what was copied was changing all the time since the selected range was random, and I couldn't get hold of what was going on. I was close to giving up until, by luck, the selected cell had a different background color. Viola!
On pc Debian x86-64 with master sources updated yesterday, I could reproduce this. Reverting https://cgit.freedesktop.org/libreoffice/core/commit/?id=fd64103319a28fedb44cdc0438887914dba396cb, the pb doesn't appear. Tamas/Eike: any thoughts here?
(In reply to Julien Nabet from comment #6) > On pc Debian x86-64 with master sources updated yesterday, I could reproduce > this. > > Reverting > https://cgit.freedesktop.org/libreoffice/core/commit/ > ?id=fd64103319a28fedb44cdc0438887914dba396cb, the pb doesn't appear. I do confirm it with bibisect-linux64-6.0 Adding Cc: to Tamas Bunth
A fix is provided by Tomaž in Jan 21 2022: commit 0c6ee963e1f089cb73e0c68a28af29d0f8d9e0df author Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> Tue Jan 18 15:34:49 2022 +0900 committer Tomaž Vajngerl <quikee@gmail.com> Fri Jan 21 10:42:02 2022 +0100 This is fixed by reverting the changed part in 'core/sc/source/ui/vba/vbarange.cxx'
(In reply to Hossein from comment #8) > A fix is provided by Tomaž in Jan 21 2022: > > commit 0c6ee963e1f089cb73e0c68a28af29d0f8d9e0df > author Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> Tue Jan 18 > 15:34:49 2022 +0900 > committer Tomaž Vajngerl <quikee@gmail.com> Fri Jan 21 10:42:02 > 2022 +0100 > > This is fixed by reverting the changed part in > 'core/sc/source/ui/vba/vbarange.cxx' Just for the record, the commit was backported to libreoffice-7-3 branch. the fix will be available in LibreOffice 7.3.1
Verified in Version: 7.4.0.0.alpha0+ / LibreOffice Community Build ID: 2f4f4cbeb8e50081d607b86b0475b93971c40ab8 CPU threads: 8; OS: Linux 5.10; UI render: default; VCL: gtk3 Locale: es-ES (es_ES.UTF-8); UI: en-US Calc: threaded @Tomaz, Thanks for fixing this issue!!