Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1008to1012
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

Code verallgemeinern

Code verallgemeinern
11.09.2008 10:57:08
Brehme
Hallo Zusammen,
ich habe hier einen Code den ich ca. 90 mal anwenden müsste. Kann mir den vielleicht jemand von euch verallgemeinern?
Code:
'Daten in Tabellenblatt
Sheets(3).Select
ActiveCell.FormulaR1C1 = "=Wochenansicht!R[4]C"
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:I1"), Type:=xlFillDefault
Range("A1:I1").Select
Rows("1:1").Select
Selection.Font.Bold = True
Range("A2").Select
ActiveCell.FormulaR1C1 = "=Wochenansicht!R[5]C"
Selection.AutoFill Destination:=Range("A2:I2"), Type:=xlFillDefault
Columns("A:A").EntireColumn.AutoFit
Range("B2:G2").Select
Selection.NumberFormat = "h:mm"
Range("H2:I2").Select
Selection.NumberFormat = "[h]:mm:ss"
Range("B2:I2").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="0"
Selection.FormatConditions(1).Interior.ColorIndex = 1
'Rahmen in Tabellenblatt
Range("A1:I2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("A1").Select
Und zwar soll Sheets.Select (3) immer zum nächsten Tabellenblatt springen (je nachdem wieviele vorhanden sind; das variiert) und in dem Tabellenblatt Wochenansicht (Blatt aus dem Daten gezogen werden) soll immer eine Zeile nach unten gesprungen werden; angefangen in der 6. Zeile. Dabei bleibt aber die Überschrift immer gleich (also Wochenansicht!R[4]C).
Wäre echt super wenn mir da jemand weiterhelfen könnte.
Danke schonmal
Gruß
Brehme

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Code verallgemeinern
11.09.2008 11:13:00
Marce
Hi,
also dein Code liese sich insgesamt wahrscheinlich noch um einiges verinfachen, aber dazu hab ich keine Zeit....
das was du suchst:
dim blatt as Worksheet
For each blatt in thisworkbook.sheets
ersetzte "Sheets(3).Select" durch "blatt.select"
[Hier kommt dein Code]
next blatt
das ganze Ding ist eine Schleife, das könntest du auch beim restlichen code anwenden such mal in der hilfe nach for next
allerdings weiß ich nicht wie gut du mit vba kannst - daher würde es auch genügen den code zu lassen und nur das obenstehende zu ändern.
Gruß
Marce
AW: Code verallgemeinern
11.09.2008 11:32:27
Brehme
Hi Marce,
erst einmal vielen Dank für deine Antwort. Bin eben nicht so fit in VBA bzw. fange gerade an damit. Der Code ist auch eine Mischung aus Recorder und selber gemacht ;-).
Leider hat das mit deinem Tipp auch nicht hingehauen. Nach dem ersten Tabellenblatt hört er auf :-(. Vielleicht kannst Du mir noch einmal helfen?
Hier noch einmal der Code:
Dim blatt As Worksheet
For Each blatt In ThisWorkbook.Sheets
blatt.Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "=Wochenansicht!R[4]C"
Selection.AutoFill Destination:=Range("A1:I1"), Type:=xlFillDefault
Range("A1:I1").Select
Selection.Font.Bold = True
Range("A2").Select
ActiveCell.FormulaR1C1 = "=Wochenansicht!R[4]C"
Selection.AutoFill Destination:=Range("A2:I2"), Type:=xlFillDefault
Columns("A:A").EntireColumn.AutoFit
Range("B2:G2").Select
Selection.NumberFormat = "h:mm"
Range("H2:I2").Select
Selection.NumberFormat = "[h]:mm:ss"
Range("B2:I2").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="0"
Selection.FormatConditions(1).Interior.ColorIndex = 1
'Rahmen in Tabellenblatt
Range("A1:I2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("A1").Select
Next blatt
Danke schonmal!
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige