Hi
I’m new to LibreOffice. I was using Excel but I’m trying to switch over to Calc. I was using the code below to find and write. I’m hoping someone could please look at the code and see what adjustments are needed to use it in Calc. Thank you.
- See attached spreadsheet for an example of the code as described below.
Code Notes:
- The code searches the range B20:B50, E20:E150, J20:J150 and I need to able to add a lot more ranges as time goes on. The code is looking for sets of numbers (eg. 1-15 or 2-10 etc.) and when found uses the first number in the set of numbers. It then searches the range G2:G16 for the first number in the set of found numbers.
In my sample spreadsheet cell B25 contains 1-10 so the code would search range G2:G16 and find cell G2 which contains 1 and would write 1-10 in cell J2 and so on.
That’s it.
Sub LINE1TO15()
Application.ScreenUpdating = False
Dim LastRow As Long, rng As Range, splitRng As Variant, fnd As Range
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each rng In Range("B20:B50, E20:E150, J20:J150")
If rng <> "" Then
splitRng = Split(rng, "-")
Set fnd = Range("G2:G16").Find(splitRng(0), LookIn:=xlValues, lookat:=xlWhole)
If Not fnd Is Nothing Then
fnd.Offset(0, 3) = rng.Address(0, 0)
End If
End If
count.ods (7.5 KB)
Next rng
Application.ScreenUpdating = True
End Sub