Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1760to1764
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

formel mit variable füllen

formel mit variable füllen
02.06.2020 11:02:15
Stefan
Hallo liebe Gemeinde,
in dem nachstehenden Makro komme ich nicht weiter.
wie muss ich die Formel nach dem ELSE ändern um mit den Variablen (e,f,g,h) die Formel in die Zelle zu schreiben.
Danke schon mal im Voraus

Sub gewicht()
Dim datum As Date, wks As Worksheet
Dim z As Range, d As Range, e As Range, f As Range, g As Range, h As Range
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
d.Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R11C4:R13C25,R[3]C,R13C4:R13C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
Else
z.Offset(15, 23).Activate
Set f = ActiveCell
Set e = f.Offset(0, 19)
Set g = f.Offset(3, 19)
Set h = f.Offset(3, 0)
ActiveCell.FormulaR1C1 = "=SUMIF(e:g,R[3]C,h:g)"
GoTo c
End If
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub

12
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: formel mit variable füllen
02.06.2020 11:35:11
Martin
Hallo Stefan,
der nachfolgende Code ist ungetestet! Prüfe mal, ob es so geht:
Sub gewicht()
Dim datum As Date, wks As Worksheet
Dim z As Range, d As Range, e As String, f As Range, g As String, h As String
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
d.Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R11C4:R13C25,R[3]C,R13C4:R13C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
Else
z.Offset(15, 23).Activate
Set f = ActiveCell
e = f.Offset(0, 19).Address(0, 0)
g = f.Offset(3, 19).Address(0, 0)
h = f.Offset(3, 0).Address(0, 0)
ActiveCell.FormulaR1C1 = "=SUMIF(" & e & ":" & g & ",R[3]C," & h & ":" & g & ")" _
GoTo c
End If
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub
Viele Grüße
Martin
Anzeige
AW: formel mit variable füllen
02.06.2020 11:46:10
Stefan
leider geht das so auch nicht
AW: formel mit variable füllen
02.06.2020 11:46:42
Stefan
leider geht das so auch nicht
AW: formel mit variable füllen
02.06.2020 12:35:00
Martin
Hallo Stefan,
mir geht es ebenso wie UweD. Ohne eine entsprechende Beispielmappe ist es sehr schwierig dir zu helfen, weil man den Code nicht testen kann.
Ich wage noch einen Versuch, wieder ungetestet:
Sub gewicht()
Dim datum As Date, wks As Worksheet
Dim z As Range, d As Range, e As String, f As Range, g As String, h As String
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
d.Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R11C4:R13C25,R[3]C,R13C4:R13C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
Else
z.Offset(15, 23).Activate
Set f = ActiveCell
e = f.Offset(0, 19).Address(ReferenceStyle:=xlR1C1)
g = f.Offset(3, 19).Address(ReferenceStyle:=xlR1C1)
h = f.Offset(3, 0).Address(ReferenceStyle:=xlR1C1)
ActiveCell.FormulaR1C1 = "=SUMIF(" & e & ":" & g & ",R[3]C," & h & ":" & g & ")" _
GoTo c
End If
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub
Viele Grüße
Martin
Anzeige
Noch eine Idee...
02.06.2020 13:29:33
Martin
Hallo Stefan,
versuche es mal noch so:
Sub gewicht()
Dim datum As Date, wks As Worksheet
Dim z As Range, d As Range, e As String, f As Range, g As String, h As String
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
d.Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = "=SUMIF(R11C4:R13C25,R[3]C,R13C4:R13C25)"
Selection.AutoFill Destination:=e, Type:=xlFillDefault
Else
z.Offset(15, 23).Activate
Set f = ActiveCell
e = f.Address(ReferenceStyle:=xlR1C1, RelativeTo:=f.Offset(0, 19))
g = f.Address(ReferenceStyle:=xlR1C1, RelativeTo:=f.Offset(3, 19))
h = f.Address(ReferenceStyle:=xlR1C1, RelativeTo:=f.Offset(3, 0))
ActiveCell.FormulaR1C1 = "=SUMIF(" & e & ":" & g & ",R[3]C," & h & ":" & g & ")" _
GoTo c
End If
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub
Viele Grüße
Martin
Anzeige
AW: formel mit variable füllen
04.06.2020 21:31:10
Stefan
danke an euch allen,
ich habe es jetzt so wie in dem unteren Makro gelöst
Sub gewicht()
Dim datum As Date, wks As Worksheet
Dim z As Range, d As Range, a As Range
Dim f1 As String, e1 As String, g1 As String, j1 As String
Dim i1 As String, h1 As String, k1 As String, g2 As String
Dim e2 As String, j2 As String
Dim k As Integer
k = 29
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, _
lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
GoTo c
d.Activate
ActiveCell.FormulaR1C1 = _
"=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination _
:=Range("AB8:AU8"), Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = _
"=SUMIF(R11C4:R13C25,R[-1]C,R13C4:R13C25)"
Selection.AutoFill Destination:=Range("AB12:AU12"), _
Type:=xlFillDefault
Else
f1 = z.Offset(14, -1).Address
e1 = z.Offset(16, 20).Address
e2 = z.Offset(20, 20).Address
g1 = z.Offset(16, -1).Address
g2 = z.Offset(20, -1).Address
i1 = z.Offset(15, 23).Address
h1 = z.Offset(18, -1).Address
k1 = z.Offset(20, 20).Address
Set i = z.Offset(15, 23)
i.Activate
j1 = i.Offset(-1, 0).Address
ActiveCell.Value = WorksheetFunction.SumIf(.Range(f1, e1), .Range(j1), .Range( _
g1, e1))
For w = 1 To 19
k = k + 1
ActiveCell = Cells(ActiveCell.Row, k)
j1 = ActiveCell.Offset(-1, 0).Address
ActiveCell.Value = WorksheetFunction.SumIf(.Range(f1, e1), .Range(j1), . _
Range(g1, e1))
ActiveCell.Offset(4, 0).Activate
j2 = ActiveCell.Offset(-1, 0).Address
ActiveCell.Value = WorksheetFunction.SumIf(.Range(h1, k1), .Range(j2), . _
Range(g2, e2))
Set i = ActiveCell.Offset(-4, 1)
i.Activate
Next w
.Protect BIOCON
z.Offset(15, -1).Activate
End If
Exit Sub
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type _
:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection. _
FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub

Anzeige
AW: formel mit variable füllen
02.06.2020 11:37:59
UweD
Hallo
ungeprüft....

ActiveCell.FormulaR1C1 = "=SUMIF(" & e & ":" & g & ",R[3]C," & h & ":" & g & ")"

LG UweD
AW: formel mit variable füllen
02.06.2020 11:47:27
Stefan
geht auch nicht
AW: formel mit variable füllen
02.06.2020 11:48:27
UweD
Dann musst du die Datei (anonymisiert und abgespeckt) hochladen
AW: formel mit variable füllen
02.06.2020 15:36:50
Gerd
Moin Stefan,
ActiveCell.FormulaR1C1 = "=SUMIF(" & e.Address(0, 0, xlR1C1) & ":" & g.Address(0, 0, xlR1C1) & ",R[3]C," & h.Address(0, 0, xlR1C1) & ":" & g.Address(0, 0, xlR1C1) & ")"
Die Variable e hat im ersten Zweig der IF-Bedingung m.E. noch keinen Wert. Oder?
Gruß Gerd
Anzeige
AW: formel mit variable füllen
02.06.2020 20:40:04
Stefan
nach dem ELSE nimmt er mir nun die koordinaten von den Zellen,
mein Problen liegt jetzt noch bei der Formel.
ich komm da nicht weiter.
Sub gewicht()
Dim datum As Date, wks As Worksheet, x As Long, y As Range
Dim z As Range, d As Range, c As Range, e As Range
Dim f As Range, g As Range, h As Range, i As Range
Set wks = Worksheets("Eingabe")
With wks
.Unprotect BIOCON
Set z = wks.Range("E:E").Find(what:=Date - 1, _
lookat:=xlWhole, LookIn:=xlValues)
Set d = wks.Cells(8, 28)
datum = "01.01." & Year(Date)
If datum = Date Then
GoTo c
d.Activate
ActiveCell.FormulaR1C1 = _
"=SUMIF(R7C4:R9C25,R[3]C,R9C4:R9C25)"
Selection.AutoFill Destination _
:=Range("AB8:AU8"), Type:=xlFillDefault
d.Offset(4, 0).Activate
ActiveCell.FormulaR1C1 = _
"=SUMIF(R11C4:R13C25,R[3]C,R13C4:R13C25)"
Selection.AutoFill Destination:=Range("AB12:AU12"), _
Type:=xlFillDefault
Else
z.Offset(14, -1).Activate
Set f = ActiveCell
f = f.Address(0, 0)
Set e = f.Offset(2, 21)
e = e.Address(0, 0)
Set g = f.Offset(2, 0)
g = g.Address(0, 0)
Set i = f.Offset(1, 24)
i.Activate
ActiveCell.FormulaR1C1 = "=SUMIF(" & f & "  "":""  " & e & ",R[-1]C, " & g & "   _
"":""  " & e & ")"
'Selection.AutoFill Destination:=Range("AB1844:AU1844"), Type:=xlFillDefault
End If
Exit Sub
c:
Columns("AB:CN").Activate
Selection.FormatConditions.Add Type _
:=xlCellValue, Operator:=xlEqual, _
Formula1:="=0"
Selection.FormatConditions(Selection. _
FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
.Protect BIOCON
z.Activate
ActiveCell.Offset(15, -1).Activate
End With
End Sub

Anzeige
AW: formel mit variable füllen
02.06.2020 21:23:34
GerdL
Moin,
ich schließe mich nun den weiteren Helfern an.
Da du "das Problem mit den Formeln" nur umschreibst, wäre eine hochgeladene Datei mit 2 Tabellenblättern, eines mit der Ausgangslage vor dem Makorstart u. eines mit dem gewollten Musterergebnis danach beim Helfen nützlich.
Gruß Gerd

169 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige