| View previous topic :: View next topic |
| Author |
Message |
seppdepp Newbie

Joined: 13 Sep 2010 Posts: 1
|
Posted: Mon Sep 13, 2010 11:35 am Post subject: findNext in Calc only delivers first match, nothing more |
|
|
Hello,
this is my first macro in OO basic. I have a spreadsheet with several tables. Each table represents one month.
On this tables there are listings, from 1-31 for each day, and in some lines there is a cell called "RK", if there were such spendings during that day.
I want to get all values of the cells next to this "RK" cells of all tables in my current table.
Example of one of the to be searched tables:
| Code: | day | subject | Roomcost | value
---------------------------------------
4 | Vers | | 5,--
6 | Vers | | 1,--
7 | Bill | RK | 16,18
8 | www | | 1,--
11 | www | | 2,--
15 | Current | RK | 95,--
15 | Water | RK | 17,--
|
I think I know how to do this, but the problem is that findFirst delivers me the first result/match but findNext is always NULL, therefore I will only get the very first match.
My current code will deliver the first match which is 7 | Bill | RK| 16,18, and nothing else, instead, just continues to the next table.
So what is wrong here?
| Code: | Sub Main
Dim oDocument as Object
Dim oSheets as object, rkSheet As Object
Dim SearchDesc As Object
Dim x As Integer, y As Integer ' Will be used to do the output coordinates
oDocument = ThisComponent
oSheets = oDocument.Sheets 'Get all sheets
y = 5
x = 8
rkSheet = oSheets.getByName("Roomcost")
For c = 0 to oSheets.Count - 1
ThisSheet = oSheets.getByIndex(c)
' Print each month's name
rkSheet.getCellByPosition(x, y).String = ThisSheet.getname()
rkSheet.getCellByPosition(x, y).CharWeight = com.sun.star.awt.FontWeight.BOLD
y = y + 1
SearchDesc = ThisSheet.createSearchDescriptor()
SearchDesc.SearchCaseSensitive = true
SearchDesc.SearchWords = true
SearchDesc.searchString="RK"
Found = ThisSheet.findFirst (SearchDesc)
Do Until IsNull(Found)
rkSheet.getCellByPosition(x, y).String = Found.string 'Test output
y = y + 1
Found = ThisSheet.findNext(Found.End, SearchDesc)
Loop
Next
End Sub |
Thank you everybody. _________________ OpenOffice 3.2.1 Mac |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8995 Location: Lexinton, Kentucky, USA
|
Posted: Mon Sep 13, 2010 4:02 pm Post subject: |
|
|
Found.End does not work in a spreadsheet. Try the following for your Do loop. | Code: | Do Until IsNull(Found)
Print Found.string
Value = ThisSheet.GetCellByPosition(Found.CellAddress.Column+1,Found.CellAddress.Row)
Print Value.value 'If text then Value.String.
Found = ThisSheet.findNext(Found, SearchDesc)
Loop |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|