siehe auch hier: https://www.herber.de/forum/messages/1152239.html
vg herbert
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count = 1 And .HasFormula Then
If LCase(Left(.Formula, 9)) = "=product(" Then
If CBool(InStr(.Formula, "163%")) Then _
.Formula = Replace(.Formula, "163%", "100%")
End If
End If
End With
End Sub
So fkt das bei mir einwandfrei. Ggf solltest du bei deinem Bsp statt "163%", "100%" besser ",163%,", ",100%," schreiben, falls das in Wirklichkeit auch mal zusätzl größere Zahlen wie 1163 an anderer Stelle enthalten kann (bei generell ohne %) oder 1.63 → 1 oder was immer nötig ist, um den Austausch eindeutig zu gestalten.Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count = 1 And .HasFormula Then
If LCase(Left(.Formula, 9)) = "=product(" Then
If CBool(InStr(.Formula, "163%")) Then _
.Formula = Replace(.Formula, "163%", "100%")
ElseIf IsArray(gromPTBFF) And _
LCase(Left(.Formula, 15)) = "=prodargtausch(" Then
If CBool(InStr(.Formula, gromPTBFF(0))) Then _
.Formula = Replace(.Formula, gromPTBFF(0), gromPTBFF(1))
End If
End If
End With
End Sub
in allgemeinem Modul des Projekts:
Option Explicit
Public gromPTBFF As Variant
Function ProdArgTausch(Bezug, Optional ByVal Faktor As Double = 1)
Const fakT As String = "163% 100%"
If Faktor = 1.63 Then gromPTBFF = Split(fakT, " ")
ProdArgTausch = Bezug * Faktor
End Function
Beide Funktionen (Abk: Fktt) machen dasselbe, nur kann die udF außerdem die (nachträgl) Änderung ihres 2.Arguments veranlassen → darauf kommt es an — nicht ändern, das ginge nur mit dem ArgWert, sondern diese nur veranlassen. Den Rest besorgt die physisch entkoppelte Ereignisprozedur bzw eine von ihr aufgerufene Subroutine. Dazu benötigt sie Angaben, die ihr von der udF mit der Public-Variablen gromPTBFF geliefert wdn.Public Function Honorar(LB$, AK, HonZone, HonSatz, AusgWert%)
Dim wsAddIn As Worksheet, HzMin1$, HzMin2$, HzMax1$, HzMax2$
Dim ak_min, ak_max, HonMin0, HonMin1, HonMax0, HonMax1
Dim Höchstsatz, Mindestsatz, s§Spalte$, sLbPM2004$
Dim iMaxHz%, sAkSpalte$, iHzSpalte%, iLastRow%, sAkRegion$, objSheet As Object
On Error GoTo ende
Call ProdArgTausch("A1", HonSatz)
Set wsAddIn = ThisWorkbook.Sheets(LB)
With wsAddIn
Application.EnableEvents = False
iLastRow = .Cells(Rows.Count, HonZone).End(xlUp).Row
iMaxHz = .Range("1:1").Find(What:="ak").Column
sAkSpalte = Chr(iMaxHz + 64)
sAkRegion = sAkSpalte & "2:" & sAkSpalte & iLastRow
iHzSpalte = iMaxHz - 2
s§Spalte = Chr(iMaxHz + 65)
If LB = "PM-2004" And AK > 50000000 Then
iHzSpalte = 3
sLbPM2004 = " + AK > 50.000.000 "
End If
If HonZone = "5 +" Or HonZone = "5+" Or HonZone > "5" Or HonZone > iHzSpalte Then
HonZone = iHzSpalte
MsgBox "Die größte HonZone für """ & LB & sLbPM2004 & """ ist """ & iHzSpalte & """." _
& vbLf & vbLf & _
"Sie wird für die Berechnung automatisch angepasst!"
End If
HzMin1 = Chr(HonZone + 64)
HzMax1 = Chr(HonZone + 65)
If HonZone = 6 Then
HzMin2 = HzMax1
HzMax2 = HzMax1
Else
HzMin2 = Chr(HonZone + 65)
HzMax2 = Chr(HonZone + 66)
End If
ak_min = .Range(sAkSpalte & Application.Match(AK, .Range(sAkRegion), 1) + 1).Value
ak_max = .Range(sAkSpalte & Application.Match(AK, .Range(sAkRegion), 1) + 2).Value
HonMin0 = .Range(HzMin1 & Application.Match(AK, .Range(sAkRegion), 1) + 1).Value
HonMin1 = .Range(HzMin2 & Application.Match(AK, .Range(sAkRegion), 1) + 1).Value
HonMax0 = .Range(HzMin1 & Application.Match(AK, .Range(sAkRegion), 1) + 2).Value
HonMax1 = .Range(HzMin2 & Application.Match(AK, .Range(sAkRegion), 1) + 2).Value
Mindestsatz = xxx
HonMin0 = .Range(HzMax1 & Application.Match(AK, .Range(sAkRegion), 1) + 1).Value
HonMin1 = .Range(HzMax2 & Application.Match(AK, .Range(sAkRegion), 1) + 1).Value
HonMax0 = .Range(HzMax1 & Application.Match(AK, .Range(sAkRegion), 1) + 2).Value
HonMax1 = .Range(HzMax2 & Application.Match(AK, .Range(sAkRegion), 1) + 2).Value
Höchstsatz = xxx
End With
If HonSatz > 1 Then
HonSatz = 1
MsgBox "Der Honorarsatz darf 100% nicht übersteigen!" & vbLf & vbLf & _
"Die Berechnung wird automatisch angepasst!" & vbLf & vbLf & _
"Bitte ändern Sie Ihre Eingaben in der Zelle!"
End If
If HonSatz = 0 Then Honorar = Mindestsatz
If HonSatz = 1 Then Honorar = Höchstsatz
If HonSatz > 0 And HonSatz
Public Function ProdArgTausch(Bezug, Optional ByVal Faktor As Double = 100)
Const fakT As String = "163% 100%"
If Faktor = 1.63 Then gromPTBFF = Split(fakT, " ")
ProdArgTausch = Bezug * Faktor
End Function
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
1 | Arg1 | Ergebnis | ||||
2 | 2000 | 3260 | ||||
3 | 3260 | |||||
4 | Arg2 | 2000 | ||||
5 | 163% | 2000 | ||||
6 | 2000 | |||||
7 | 2000 |
Function ProdArgTausch(Bezug, Optional ByVal Faktor As Double = 1)
Const fakT As String = "163% 100%"
Dim ft As Variant, ac As Range
If Round(Faktor, 2) = 1.63 Then
ft = Split(fakT, " ")
Set ac = Application.Caller
If InStr(ac.Formula, ft(0)) = 0 Then
ft(0) = Mid(ac.Formula, InStrRev(ac.Formula, ",") + 1)
ft(0) = Left(ft(0), Len(ft(0)) - 1)
End If
gromPTBFF = ft
End If
ProdArgTausch = Bezug * Faktor
Set ac = Nothing
End Function
Alles weitere dann später!