F
| Problem | Makro |
| Fehlerbehandlung: Das Makro wir trotz "On Error Resume Next" unterbrochen | Im VBA Editor unter Extras Optionen Allgemein gibt es den Punkt Fehlerbehandlung der steht vermutlich auf "Bei jedem Fehler unterbrechen" ändere das auf "Bei nichtverarbeiteten Fehler unterbrechen" |
| Farbtabelle | Siehe Extraseite |
| Nach Zahlenbereichen den Eintrag Farbig formatieren | 'Formatiert 1-9 schwarz, 10-19 rot, 20-29 grün, usw. 'Zu formatierenden Bereich selektieren Sub Farbig() Dim C As Range For Each C In Selection On Error Resume Next If C < 920 Then C.Font.ColorIndex = 1 Else If C >= 1 And C < 10 Then C.Font.ColorIndex = 3 Else If C >=10 And C <20 Then C.Font.ColorIndex = 4 Else If C >= 20 And C < 30 Then C.Font.ColorIndex = 5 Else If C >= 30 And C < 40 Then C.Font.ColorIndex = 6 Else If C >= 40 Then C.Font.ColorIndex = 7 End If End If End If End If End If End If Next C End Sub 'Die Farbanpassung erfolgt bei "C.Font.ColorIndex = Zahl" 'Schwarz ist 1, Weiß 2, Rot 3, Grün 4 usw. Siehe Extraseite |
| Zelle nach Erstem Zahlenwert farbig ausfüllen (wäre auch mehrstellig möglich) | Sub Farben() Spalte = 1 'Hier Spaltennummer ändern Ende = Cells(Rows.Count, Spalte).End(xlUp).Row For i = 1 To Ende Select Case Left(Cells(i, Spalte), 1) Case Is = 1 Cells(i, Spalte).Interior.ColorIndex = 3 Case Is = 2 Cells(i, Spalte).Interior.ColorIndex = 4 Case Is = 3 Cells(i, Spalte).Interior.ColorIndex = 5 Case Is = 4 Cells(i, Spalte).Interior.ColorIndex = 6 Case Is = 5 Cells(i, Spalte).Interior.ColorIndex = 7 Case Is = 6 Cells(i, Spalte).Interior.ColorIndex = 8 Case Is = 7 Cells(i, Spalte).Interior.ColorIndex = 9 Case Is = 8 Cells(i, Spalte).Interior.ColorIndex = 10 Case Is = 9 Cells(i, Spalte).Interior.ColorIndex = 11 Case Is = 0 Cells(i, Spalte).Interior.ColorIndex = 12 Case Else End Select Next i End Sub 'Die Farbanpassung erfolgt bei ".Interior.ColorIndex = Zahl" 'Schwarz ist 1, Weiß 2, Rot 3, Grün 4 usw. Siehe Extraseite |
| Farben in Makros | Sub farbe1() 'alle Zellen der aktiven Tabelle Cells.Interior.ColorIndex = 15 End Sub Sub farbe2() 'Truecolor Farbzuweisung [a1].Interior.Color = RGB(200, 250, 250) [a2].Interior.Color = RGB(240, 155, 255) End Sub Sub farbe3() 'Rahmen einfärben [a3:A55].Borders.ColorIndex = 3 End Sub Sub farbe4() 'Spalte 2 ohne Farbe Columns(2).Interior.ColorIndex = xlColorIndexNone 'Schleife für alle colorindex For x = 1 To 56 Cells(x, 2) = "Farbe " & x Cells(x, 2).Font.ColorIndex = x Cells(x, 3).Interior.ColorIndex = x Next x End Sub Sub farbe5() [d1] = "Test" 'Einzelne Buchstaben farbig With [d1] .Font.Bold = True .Characters(1, 1).Font.ColorIndex = 3 .Characters(2, 1).Font.ColorIndex = 4 .Characters(3, 1).Font.ColorIndex = 5 .Characters(4, 1).Font.ColorIndex = 6 End With End Sub |
| Formeln in Zellen per Makro eintragen | Es gibt 2 Möglichkeiten Formeln in Zellen zu
Schreiben:: 1. man benutzt "Formula" und die englischen Funktionsnamen 2. man benutzt "FormulaLocal" Sub test1() 'Funktioniert ActiveCell.Formula = "=sum(A1:B1)" End Sub Sub test2() 'Funktioniert ActiveCell.FormulaLocal = "=summe(A1:B1)" End Sub Sub test0() |
| Feiertage berechnen | siehe: Benutzerdefinierte Funktionen |