ich habe ein kleines Problem mit der Bedingten Formatierung als Makro.
Ist es möglich als Ziel eine berechnete Zelle
z.B. durch
Code: Alles auswählen
oSSFZiel1 = oSSSheet.getcellbyposition(18,nSSFRow-9)
Code: Alles auswählen
oSSFZ1 = oSSSheet.getcellbyposition(18,nSSFRow-9)
oSSFZiel1 = oSSFZ1.getCellAddress
Die bedingte Formatierung wird richtig gesetzt, nur das als Werte 0 da steht (oder bei der Nutzung von "" in .Value dann oSSFZiel1)
Ich habe eine abgespeckte Version der Tabelle auch im Anhang.
Und hier einmal das komplette Makro:
Code: Alles auswählen
REM ***** BASIC *****
Sub Add_Row
oSoap = thisComponent
oBASheet = oSoap.Sheets().getByName("Batch Amounts")
oSSSheet = oSoap.Sheets().getByName("Sugar Scrub Soaps")
oCBACell = oBASheet.getCellRangeByName("VO17:WH32")
oCSSCell = oSSSheet.getCellRangeByName("VO16:WM31")
oBACursor = oBASheet.createCursor
oBACursor.GotoEndOfUsedArea(False)
nBARow = oBACursor.getRangeAddress().endRow
oBACell = oBASheet.getcellbyposition(0,nBARow+1)
oCBARange = oCBACell.getRangeAddress
oBARange = oBACell.getCellAddress
oBASheet.copyRange(oBARange,oCBARange)
oSSCursor = oSSSheet.createCursor
oSSCursor.GotoEndOfUsedArea(False)
nSSRow = oSSCursor.getRangeAddress().endRow
oSSCell = oSSSheet.getcellbyposition(0,nSSRow+1)
oCSSRange = oCSSCell.getRangeAddress
oSSRange = oSSCell.getCellAddress
oSSSheet.copyRange(oSSRange,oCSSRange)
Dim oSSFCell1 as Object
Dim oSSFCell2 as Object
Dim oSSFCell3 as Object
Dim oSSFCell4 as Object
Dim oConditionalForm as Object
Dim oConditionalForm2 as Object
oSSFCursor = oSSSheet.createCursor
oSSFCursor.GotoEndOfUsedArea(False)
nSSFRow = oSSFCursor.getRangeAddress().endRow
oSSFCell1 = oSSSheet.getcellbyposition(12,nSSFRow-4)
oSSFCell2 = oSSSheet.getcellbyposition(12,nSSFRow-11)
oSSFCell3 = oSSSheet.getcellbyposition(18,nSSFRow-7)
oSSFCell4 = oSSSheet.getcellbyposition(12,nSSFRow-8)
oSSFZ1 = oSSSheet.getcellbyposition(18,nSSFRow-9)
oSSFZ2 = oSSSheet.getcellbyposition(18,nSSFRow-4)
oSSFZiel1 = oSSFZ1.getCellAddress
oSSFZiel2 = oSSFZ2.getCellAddress
oConditionalForm = oSSFCell1.ConditionalFormat
oConditionalForm = oSSFCell2.ConditionalFormat
oConditionalForm = oSSFCell3.ConditionalFormat
Dim oCondition1(3) as New com.sun.star.beans.PropertyValue
oCondition1(0).Name = "Operator"
oCondition1(0).Value = com.sun.star.sheet.ConditionOperator.LESS
oCondition1(1).Name = "Formula1"
oCondition1(1).Value = oSSFZiel1
oCondition1(2).Name = "StyleName"
oCondition1(2).Value = "Negativ - Rot"
oConditionalForm.addNew( oCondition1() )
oCondition1(0).Value = com.sun.star.sheet.ConditionOperator.EQUAL
oCondition1(1).Name = "Formula1"
oCondition1(1).Value = oSSFZiel1
oCondition1(2).Name = "StyleName"
oCondition1(2).Value = "Mittelwert - Gelb"
oConditionalForm.addNew( oCondition1() )
oCondition1(0).Value = com.sun.star.sheet.ConditionOperator.GREATER
oCondition1(1).Name = "Formula1"
oCondition1(1).Value = oSSFZiel1
oCondition1(2).Name = "StyleName"
oCondition1(2).Value = "Positiv - Grün"
oConditionalForm.addNew( oCondition1() )
oSSFCell1.ConditionalFormat = oConditionalForm
oSSFCell2.ConditionalFormat = oConditionalForm
oSSFCell3.ConditionalFormat = oConditionalForm
oConditionalForm2 = oSSFCell4.ConditionalFormat
Dim oCondition2(3) as New com.sun.star.beans.PropertyValue
oCondition2(0).Name = "Operator"
oCondition2(0).Value = com.sun.star.sheet.ConditionOperator.LESS
oCondition2(1).Name = "Formula1"
oCondition2(1).Value = "oSSFZiel2*2"
oCondition2(2).Name = "StyleName"
oCondition2(2).Value = "Negativ - Rot"
oConditionalForm2.addNew( oCondition2() )
oCondition2(0).Value = com.sun.star.sheet.ConditionOperator.BETWEEN
oCondition2(1).Name = "Formula1"
oCondition2(1).Value = "oSSFZiel2*2"
oCondition2(1).Name = "Formula2"
oCondition2(1).Value = oSSFZiel1
oCondition2(2).Name = "StyleName"
oCondition2(2).Value = "Mittelwert - Gelb"
oConditionalForm2.addNew( oCondition2() )
oCondition2(0).Value = com.sun.star.sheet.ConditionOperator.GREATER
oCondition2(1).Name = "Formula1"
oCondition2(1).Value = oSSFZiel1
oCondition2(2).Name = "StyleName"
oCondition2(2).Value = "Positiv - Grün"
oConditionalForm2.addNew( oCondition2() )
oSSFCell4.ConditionalFormat = oConditionalForm2
End Sub
Durch drücken auf die Schaltfläche "Add Row" im sheet "Batch Amounts" wird eine neue Tabelle in beiden Sheets hinzugefügt.
Nun sollen 4 der neu erstellten Zellen eine Bedingte Formatierung bekommen.
Und wenn es Vorschläge dazu gibt wie ich eventuell das Makro übersichtlicher machen kann nehme ich diese auch gerne Ist mein erstes Makro. ^^
Danke und LG Benny
Edit:
Gibt es auch die Möglichkeit in die Letzte Aktive Zelle in einer bestimmten Spalte zu springen?