von retuwe61 » Do, 04.10.2012 21:12
Hallo miteinander.
In Tabelle1, Spalte B, befinden sich Zahlen, u. a. mehrfach die selben. In Spalte A ein zugeordneter Begriff. Es werden zunächst nur die Duplikate benötigt.
Anschließend sollen gemäß Häufigkeit die zugeordneten Begriffe in die nachfolgenden Spalten der jeweils ersten Zahl eingetragen werden.
Danach benötige ich die Duplikate nicht mehr.
Ich hatte es vorher mit dem Datenpiloten versucht, was jedoch nicht zum gewünschten Erfolg führte. Sieht jemand eine komfortabele Lösung?
Die Originaltabelle beinhaltet mehrere tausend Zeilen.
in gespannt.
Code: Alles auswählen
Sub Formel
oDoc = thisComponent
oSheet = oDoc.Sheets.getByName ("Tabelle1")
myView = oDoc.CurrentController
oCursor = oSheet.createCursor
oCursor.gotoStart(True)
oCursor.GotoEndOfUsedArea(True)
letzte_Zeile = oCursor.getRangeAddress.EndRow+1
letzte_Spalte= oCursor.getRangeAddress.EndColumn
oRange = oSheet.getCellRangeByPosition(0,0,1,letzte_Zeile)
REM Sortieren
Dim aSortFields(0) As New com.sun.star.util.SortField
Dim aSortDesc(1) As New com.sun.star.beans.PropertyValue
aSortFields(0).Field = 1
aSortFields(0).SortAscending = Ascending
aSortFields(0).FieldType = com.sun.star.util.SortFieldType.AUTOMATIC
aSortDesc(0).Name = "SortFields"
aSortDesc(0).Value = aSortFields()
aSortDesc(1).Name = "ContainsHeader"
aSortDesc(1).Value = bhasHeader
oRange.sort(aSortDesc())
SortCalcTable=True
myCell=oSheet.getCellbyposition(1,letzte_Zeile)
myView.select(oCell)
myCell=oDoc.getCurrentSelection().getCellAddress()
oRow=myCell.Row
oColumn=myCell.column
myCell=oSheet.getCellByPosition(ocolumn,orow)
oColumnname=myCell.getColumns.getByIndex(0).getName()
cellname=ocolumnname+ltrim(str(orow))
REM Formel Häufigkeit in Spalte C
oCell = oSheet.getCellbyposition(2,1)
oCell.Formula = "=countif($B$2:$B$"+letzte_Zeile+";B2)"
oRange = oSheet.getCellRangeByPosition(2,1,2,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
aDat = oRange.getDataArray()
oRange.setDataArray(aDat)
For i = 1 To letzte_Zeile
If oSheet.GetCellByPosition(2, i).Value = "1" Then
oSheet.Rows.removeByIndex(i,1)
i = i - 1
letzte_Zeile = letzte_Zeile - 1
End If
Next i
REM Formel Zustand 1
oCell = oSheet.getCellbyposition(3,1)
oCell.FormulaLocal = "=WENN(C2>1;A2;"""")"
oRange = oSheet.getCellRangeByPosition(3,1,3,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel Zustand 2
oCell = oSheet.getCellbyposition(4,1)
oCell.FormulaLocal = "=WENN(C2>1;A3;"""")"
oRange = oSheet.getCellRangeByPosition(4,1,4,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel Zustand 3
oCell = oSheet.getCellbyposition(5,1)
oCell.FormulaLocal = "=WENN(C2>2;A4;"""")"
oRange = oSheet.getCellRangeByPosition(5,1,5,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel zur Zustand X?
REM Formeln gegen Werte austauschen
oRange = oSheet.getCellRangeByPosition(3,1,5,letzte_Zeile)
aDat = oRange.getDataArray()
oRange.setDataArray(aDat)
end sub
Gruß
Uwe
- Dateianhänge
-
- Test.ods
- (13.98 KiB) 122-mal heruntergeladen
Hallo miteinander.
In Tabelle1, Spalte B, befinden sich Zahlen, u. a. mehrfach die selben. In Spalte A ein zugeordneter Begriff. Es werden zunächst nur die Duplikate benötigt.
Anschließend sollen gemäß Häufigkeit die zugeordneten Begriffe in die nachfolgenden Spalten der jeweils ersten Zahl eingetragen werden.
Danach benötige ich die Duplikate nicht mehr.
Ich hatte es vorher mit dem Datenpiloten versucht, was jedoch nicht zum gewünschten Erfolg führte. Sieht jemand eine komfortabele Lösung?
Die Originaltabelle beinhaltet mehrere tausend Zeilen.
in gespannt.
[code]Sub Formel
oDoc = thisComponent
oSheet = oDoc.Sheets.getByName ("Tabelle1")
myView = oDoc.CurrentController
oCursor = oSheet.createCursor
oCursor.gotoStart(True)
oCursor.GotoEndOfUsedArea(True)
letzte_Zeile = oCursor.getRangeAddress.EndRow+1
letzte_Spalte= oCursor.getRangeAddress.EndColumn
oRange = oSheet.getCellRangeByPosition(0,0,1,letzte_Zeile)
REM Sortieren
Dim aSortFields(0) As New com.sun.star.util.SortField
Dim aSortDesc(1) As New com.sun.star.beans.PropertyValue
aSortFields(0).Field = 1
aSortFields(0).SortAscending = Ascending
aSortFields(0).FieldType = com.sun.star.util.SortFieldType.AUTOMATIC
aSortDesc(0).Name = "SortFields"
aSortDesc(0).Value = aSortFields()
aSortDesc(1).Name = "ContainsHeader"
aSortDesc(1).Value = bhasHeader
oRange.sort(aSortDesc())
SortCalcTable=True
myCell=oSheet.getCellbyposition(1,letzte_Zeile)
myView.select(oCell)
myCell=oDoc.getCurrentSelection().getCellAddress()
oRow=myCell.Row
oColumn=myCell.column
myCell=oSheet.getCellByPosition(ocolumn,orow)
oColumnname=myCell.getColumns.getByIndex(0).getName()
cellname=ocolumnname+ltrim(str(orow))
REM Formel Häufigkeit in Spalte C
oCell = oSheet.getCellbyposition(2,1)
oCell.Formula = "=countif($B$2:$B$"+letzte_Zeile+";B2)"
oRange = oSheet.getCellRangeByPosition(2,1,2,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
aDat = oRange.getDataArray()
oRange.setDataArray(aDat)
For i = 1 To letzte_Zeile
If oSheet.GetCellByPosition(2, i).Value = "1" Then
oSheet.Rows.removeByIndex(i,1)
i = i - 1
letzte_Zeile = letzte_Zeile - 1
End If
Next i
REM Formel Zustand 1
oCell = oSheet.getCellbyposition(3,1)
oCell.FormulaLocal = "=WENN(C2>1;A2;"""")"
oRange = oSheet.getCellRangeByPosition(3,1,3,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel Zustand 2
oCell = oSheet.getCellbyposition(4,1)
oCell.FormulaLocal = "=WENN(C2>1;A3;"""")"
oRange = oSheet.getCellRangeByPosition(4,1,4,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel Zustand 3
oCell = oSheet.getCellbyposition(5,1)
oCell.FormulaLocal = "=WENN(C2>2;A4;"""")"
oRange = oSheet.getCellRangeByPosition(5,1,5,letzte_Zeile)
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
REM Formel zur Zustand X?
REM Formeln gegen Werte austauschen
oRange = oSheet.getCellRangeByPosition(3,1,5,letzte_Zeile)
aDat = oRange.getDataArray()
oRange.setDataArray(aDat)
end sub [/code]
Gruß
Uwe