Ask Your Question
1

Convert VBA to Basic LO

asked 2018-03-22 17:46:15 +0200

BDA5 gravatar image

updated 2018-03-23 11:25:52 +0200

Hello Everyone! I have a VBA macro that I need help converting to LibreOffice Basic. What the macro does is clear the content in a variable range and then display some dates in that same space. Here is the macro in VBA!

Further explanation about the macro: This macro was created to select a range starting in cell A20 of the worksheet "Consultar" and the last cell should be the last one in collumn A that has content (that's why it is a variable range). After selecting this range the macro deletes its content.

Write Dates Part: Here what it does is subtract to dates (G4 - G3 - 1 day) and this play the dates starting in cell A20 and going down. For example if G4 is 25/May/2018 and G3 is 21/May/2018 the macro displays in A20 21/May/2018; A21 22/May/2018; A22 23/May/2018; A23 24/May/2018. The date in G4 never appears in this range.

If you have any doubt about the macro let me know.

Thanks in advance for your help!

Sub WriteDates()

' Clear Contents
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range

Set sht = Worksheets("Consultar")
Set StartCell = Range("A20")


' Find Last Row
LRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row

Range("A20:A" & LRow).ClearContents


' Write Dates
Dim rng As Range
Dim StartRng As Range
Dim EndRng As Range
Dim OutRng As Range
Dim StartValue As Variant
Dim EndValue As Variant
xTitleId = "KutoolsforExcel"
Set StartRng = Application.Selection
Set StartRng = Range("G3")
Set EndRng = Range("G4")
Set OutRng = Range("A20")
Set OutRng = OutRng.Range("A1")
StartValue = StartRng.Range("A1").Value
EndValue = EndRng.Range("A1").Value
If EndValue - StartValue <= 0 Then
Exit Sub
End If
ColIndex = 0
For i = StartValue To EndValue - 1
    OutRng.Offset(ColIndex, 0) = i
    ColIndex = ColIndex + 1
Next
End Sub
edit retag flag offensive close merge delete

Comments

Quoting @BDA5: "...clear the content in a variable range and then display some dates in that same space.."
That's yor view. As I wouldn't assume yous know LibO Basic at a high level, you shouldn't assume everybody her speaks Excel-VBA. I myself, e.g. don't at all. You will have to explain detailed what you want to achieve.
Please do it in clear words and sufficiently complete. Beyond that, concise is good.
Please edit your question for the purpose. (Don't post the explanation as an ans

Lupp gravatar imageLupp ( 2018-03-23 00:00:39 +0200 )edit

sorry for that. The explanation is added to the question. Thank you

BDA5 gravatar imageBDA5 ( 2018-03-23 11:26:44 +0200 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2018-03-23 12:36:23 +0200

Lupp gravatar image

updated 2018-03-23 12:47:37 +0200

Well, VB and the means usable from LibreOffice Basic look similar in some cases. However there are relevant differences lying in the depth of the design, and someone wanting to port VBA code to LibO should basically consider if this is the appropriate way. In most cases it's not, I would claim.

If you decide differently, you will have a next case. Thus you shold study the basic guide (here e.g.) and learn about the API, the usage of interfaces and services. What this is about you may learn from the famous texts by Andrew Pitonyak ( to find here).

Well, I could do it. But before I consider to help you this way, you will have to explaint to me for what reasons a solution without "macros" as demonstrated in this attached example is not applicable in your case. After all, using macros to make office documents work is basically evil, and only acceptable under rare conditions. That MS tells us otherwise is just a reinforcement of that claim in my view.

(The example will only work in a not too oöld version of LibO as it uses the IFERROR() function.)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-22 17:46:15 +0200

Seen: 2,453 times

Last updated: Mar 23 '18