Bug 170408 - With VBA BASIC, copying values of empty cells does not give empty cells
Summary: With VBA BASIC, copying values of empty cells does not give empty cells
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
25.8.4.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2026-01-20 22:49 UTC by documentfoundation.showoff307
Modified: 2026-02-01 13:37 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
MWE (5.08 KB, application/vnd.ms-excel.sheet.macroenabled.12)
2026-01-21 00:32 UTC, documentfoundation.showoff307
Details
Macro embedded in file (13.63 KB, application/vnd.ms-excel.sheet.macroenabled.12)
2026-01-21 12:12 UTC, Regina Henschel
Details
macro with VBASupport made by LibreOffice (9.74 KB, application/vnd.oasis.opendocument.spreadsheet)
2026-01-21 12:15 UTC, Regina Henschel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description documentfoundation.showoff307 2026-01-20 22:49:15 UTC
Description:
I expect the following macro to overwrite the value of A1 with that of B1 everytime:

Sub Bugged
Cells(1,1).Value=Cells(1,2).Value
End Sub

However, when B1 is empty, it instead does not change the value of A1.

Steps to Reproduce:
1. Write these macros in BASIC:
 
Sub Bugged
Cells(1,1).Value=Cells(1,2).Value
End Sub

Sub Fix
If Cells(1,2).Value = "" Then  Cells(1,1).value="" Else Cells(1,1).value=Cells(1,2).Value
End Sub

2. Fill A1 with 1 and B1 with 2, run the macros.
3. Fill A1 with 1 and leave B1 empty, run the macros

Actual Results:
For Step 2, both overwrite A1 with 2.
For Step 3, Bugged leaves A1 at 1, while Fix makes A1 empty.

Expected Results:
For Step 2: Same as actual
For Step 3: Bugged should also make A1 empty


Reproducible: Always


User Profile Reset: No

Additional Info:
It may be that Cells(1,2).Value returns some kind of error instead of an empty cell and the macro then cannot assign this error as a value and thus does nothing instead.
Comment 1 Regina Henschel 2026-01-21 00:09:37 UTC
(In reply to documentfoundation.showoff307 from comment #0)

> Steps to Reproduce:
> 1. Write these macros in BASIC:
>  
> Sub Bugged
> Cells(1,1).Value=Cells(1,2).Value
> End Sub
> 
> Sub Fix
> If Cells(1,2).Value = "" Then  Cells(1,1).value="" Else
> Cells(1,1).value=Cells(1,2).Value
> End Sub

Those macros do not run at all. Please attach a spreadsheet file, that contains macros that at least run.
Comment 2 documentfoundation.showoff307 2026-01-21 00:32:34 UTC
Created attachment 205110 [details]
MWE
Comment 3 documentfoundation.showoff307 2026-01-21 00:34:49 UTC
Okay, apparently it needs the 

Option VBASupport 1

So, this is a VBA Support issue. As it was not in the specific module i tested it with before, i did not know that. minimum working example attached, unsure if the xlsm format is relevant.
Comment 4 Regina Henschel 2026-01-21 12:09:26 UTC
The emptiness of cell B1 makes cell A1 empty on value assignment in Excel. LibreOffice does not change the value of cell A1 in this case. As VBASupport it introduced to be compatible with Excel macros, the behavior in LibreOffice should be changed to that of Excel.
Comment 5 Regina Henschel 2026-01-21 12:12:18 UTC
Created attachment 205116 [details]
Macro embedded in file

Replaces previous attachment "205110: MWE" because that one does not contain any macro.
Comment 6 Regina Henschel 2026-01-21 12:15:50 UTC
Created attachment 205117 [details]
macro with VBASupport made by LibreOffice

The macro
Option VBASupport 1

Sub FromB1ToA1()
Cells(1, 1).Value = Cells(1, 2).Value
End Sub

directly written in LibreOffice.

The behavior was tested in Version: 25.8.4.2 (X86_64)
Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df
CPU threads: 32; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Vulkan; VCL: win
Locale: de-DE (de_DE); UI: en-US
Calc: threaded