von clag » Mi, 29.04.2015 18:22
hallo Gast und alle anderen,
habe mal für dein Anliegen ein Makro erstellt, das deine Wünsche und etwas mehr erfüllt
also einen Textstring in einer Zelle in eine Formel wandeln,
oder einen solchen FormelString aus einer andern Zelle holen und als Formel einfügen.
Für einzelne Zellen oder markierte Bereiche
Code: Alles auswählen
Sub TextToFormula
oCalc = thisComponent
osheet = oCalc.CurrentController.ActiveSheet
sQFx = "QuickFormula"
if InStr(oCalc.Currentselection.absoluteName,";") > 1 then
nRanges = oCalc.CurrentSelection.Count
else
nRanges = 1
end if
for N=0 to nRanges-1
if nRanges =1 then oRangeAddress = oCalc.CurrentSelection.RangeAddress
if nRanges >1 then
oRangeAddress = oCalc.CurrentSelection.RangeAddresses(N)
end if
StartC = oRangeAddress.StartColumn
StartR = oRangeAddress.StartRow
LastC = oRangeAddress.EndColumn
LastR = oRangeAddress.EndRow
for C=StartC to LastC
for R=StartR to LastR
myFormulatext = oSheet.getCellByPosition(C,R).Formula
if myFormulatext="" or Left(myFormulatext,1)="=" then
goto jump:
else
if left(myFormulatext,3)="QFx" and _
oCalc.NamedRanges.hasByName(sQFx & mid(myFormulatext,4)) then
sFstring = oSheet.getCellRangeByName(sQFx & mid(myFormulatext,4)).Formula
sFString = "=" & join(split(sFstring,"“"),"""")
oSheet.getCellByPosition(C,R).FormulaLocal = sFString
else
oSheet.getCellByPosition(C,R).FormulaLocal = "=" & myFormulatext
end if
end if
jump:
next
next
next
End Sub
viel Spaß und Erfolg damit
PS
Karolus war wieder etwas schneller dafür ist mein Makro vielleicht etwas universeller und komfortabler

hallo Gast und alle anderen,
habe mal für dein Anliegen ein Makro erstellt, das deine Wünsche und etwas mehr erfüllt
also einen Textstring in einer Zelle in eine Formel wandeln,
oder einen solchen FormelString aus einer andern Zelle holen und als Formel einfügen.
Für einzelne Zellen oder markierte Bereiche
[code]
Sub TextToFormula
oCalc = thisComponent
osheet = oCalc.CurrentController.ActiveSheet
sQFx = "QuickFormula"
if InStr(oCalc.Currentselection.absoluteName,";") > 1 then
nRanges = oCalc.CurrentSelection.Count
else
nRanges = 1
end if
for N=0 to nRanges-1
if nRanges =1 then oRangeAddress = oCalc.CurrentSelection.RangeAddress
if nRanges >1 then
oRangeAddress = oCalc.CurrentSelection.RangeAddresses(N)
end if
StartC = oRangeAddress.StartColumn
StartR = oRangeAddress.StartRow
LastC = oRangeAddress.EndColumn
LastR = oRangeAddress.EndRow
for C=StartC to LastC
for R=StartR to LastR
myFormulatext = oSheet.getCellByPosition(C,R).Formula
if myFormulatext="" or Left(myFormulatext,1)="=" then
goto jump:
else
if left(myFormulatext,3)="QFx" and _
oCalc.NamedRanges.hasByName(sQFx & mid(myFormulatext,4)) then
sFstring = oSheet.getCellRangeByName(sQFx & mid(myFormulatext,4)).Formula
sFString = "=" & join(split(sFstring,"“"),"""")
oSheet.getCellByPosition(C,R).FormulaLocal = sFString
else
oSheet.getCellByPosition(C,R).FormulaLocal = "=" & myFormulatext
end if
end if
jump:
next
next
next
End Sub
[/code]
[attachment=0]textFormula_to_activeFormula.ods[/attachment]
viel Spaß und Erfolg damit
PS
Karolus war wieder etwas schneller dafür ist mein Makro vielleicht etwas universeller und komfortabler :D