在给定一系列列的情况下,使用 LibreCalc 中的 StarBasic 使用宏减去列位置,例如。 A1:B1 - 必须结果 1

Subtract column position using Macros using StarBasic in LibreCalc given a range of columns eg. A1:B1 - must result 1

在给定一系列列的情况下,使用 LibreCalc 中的 VBA (libre StarBasic) 宏减去列位置,例如。 A1:B1 必须结果 1

我有一组范围 我想在 Libre Calc 中使用 VBA 宏将列位置差作为整数 例如

B17:C28,E17:G28,L17:O28

It must results (C-B) = 1, G-E = 2, O - L = 3

我该怎么做?

我不得不对 ActiveSheet.getCellRangeByName("a1:a1") 使用“Columns.Count”来获取范围中减去列位置的信息。

Dim sDataRng 'Where is the data


' Constant with ranges
Const SCells = "B1:C1,E1:G1,L1:1"

' split constant using as separator ",".
aCells = Split(SCells,",")
 

Sub subtract_column_position 

for i  = 0 to 2 step 1  
            
        ActiveSheet = ThisComponent.CurrentController.ActiveSheet
        sDataRng    = aCells(i)
        oRange      = ActiveSheet.getCellRangeByName(aCells(i))

        print oRange.Columns.Count - 1

next i 

end sub