53111
Goto Top

VBA in Excel Schrift in bestimmter zeile Dick machen

hallo ich habe folgendes Problem ich möchte dass per vba in einer bestimmten zeile die schrift dick gemacht wird.

ich habe folgendes angefangen. das schlüsselwort ist "Gesamt:". alles in der zeile in der Gesamt steht soll dick gemacht werden?


Dim auswahl As Range
For Each auswahl In Range("A1:C51")
If cell.Value = "Gesamt:" Then
cell.Font.Bold = True
End If
Next

Content-Key: 71162

Url: https://administrator.de/contentid/71162

Printed on: April 19, 2024 at 02:04 o'clock

Member: wakko
wakko Oct 17, 2007 at 08:25:36 (UTC)
Goto Top
Moin,

ich würde das so machen:
Dim i%
i = 1
With ActiveSheet
Do Until .Cells(i, 1).Value = ""  
    If .Cells(i, 1).Value = "Gesamt:" Then  
        .Rows(i & ":" & i).Select  
        Selection.Font.Bold = True
    End If
    i = i + 1
Loop
End With

Nich tschön, aber läuft...

Gruß,
Henrik
Mitglied: 8644
8644 Oct 17, 2007 at 09:37:49 (UTC)
Goto Top
Hi,

muß es unbedingt VBA sein? Für solche Zwecke gibt es doch eigentlich die Bedingte Formatierung.
Also ungefähr so:
- Bereich markieren
- Menü Format -> Bedingte Formatierung
- Formel ist
- =$A1="Gesamt"
- Bei Format Fett einstellen

Psycho
Mitglied: 53111
53111 Oct 17, 2007 at 09:42:26 (UTC)
Goto Top
das problem ist dass sich die zeile an der "Gesamt" steht immer wieder ändert? die inhalte der Tabelle werden aus einer anderen tabelle geholt?

Dim i%
i = 1
With ActiveSheet
Do Until .Cells(i, 1).Value = ""
If .Cells(i, 1).Value = "Gesamt:" Then
.Rows(i & ":" & i).Select
Selection.Font.Bold = True
End If
i = i + 1
Loop
End With

hat bei mir leider nicht funktioniert? wie spreche ich denn eine andere Tabelle in der excel mappe an? glaube es hat was mit dem activesheet zu tun, dass es nicht funktioniert?
Member: wakko
wakko Oct 17, 2007 at 11:53:37 (UTC)
Goto Top
Na dan machst du aus AvtiveSheet -> ActiveWorkbook.Sheets(1) für das erster usw.
Mitglied: 53111
53111 Oct 18, 2007 at 07:56:05 (UTC)
Goto Top
ok ich habe das jetzt wie folgt gemacht:

[code]
Sub DeleteRowIfEmptyCell()


Set Bereich = Range("A1:C51")
For Each Zelle In Bereich
If Zelle.Value = "0" Then
Zelle.Value = ""
End If
Next

Dim intRow As Integer, intLastRow As Integer, letzte As Integer

intLastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
For intRow = intLastRow To 1 Step -1
If Application.CountA(Rows(intRow)) = 0 Then
intLastRow = intLastRow - 1
Else
Exit For
End If
Next intRow
For intRow = intLastRow To 1 Step -1
If IsEmpty(Cells(intRow, 1)) Then
Rows(intRow).Delete
End If
Next intRow


Dim i%
i = 1
With ActiveWorkbook.Sheets(2)
Do Until .Cells(i, 1).Value = ""
If .Cells(i, 1).Value = "Gesamt:" Then
.Rows(i & ":" & i).Select
Selection.Font.Bold = True
End If
i = i + 1
Loop
End With


Sheets("Liste für Word").Select


End Sub [/code]


jetzt erscheint der fehler "400"? und es wird nichts dick gezeichnet
Member: bastla
bastla Oct 22, 2007 at 20:21:55 (UTC)
Goto Top
Hallo saibonaut!

Bei mir läuft dieser (fast unveränderte Code) problemlos durch (zumindest hinsichtlich der Fett-Formatierung ab der Zeile "i=1" sehe ich überhaupt kein Problem):
Sub DeleteRowIfEmptyCell()

Set Bereich = Range("A1:C51")  
For Each Zelle In Bereich
    If Zelle.Value = "0" Then Zelle.Value = ""  
Next

Dim intRow As Integer, intLastRow As Integer, letzte As Integer

intLastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
For intRow = intLastRow To 1 Step -1
    If Application.CountA(Rows(intRow)) = 0 Then
        intLastRow = intLastRow - 1
    Else
        Exit For
    End If
Next

For intRow = intLastRow To 1 Step -1
    If IsEmpty(Cells(intRow, 1)) Then Rows(intRow).Delete
Next

i = 1
With ActiveWorkbook.Sheets(2)
    Do Until .Cells(i, 1).Value = ""  
        If .Cells(i, 1).Value = "Gesamt:" Then  
            .Rows(i & ":" & i).Font.Bold = True  
        End If
        i = i + 1
    Loop
End With

Sheets("Liste für Word").Select  

End Sub

Für welche Zeile wurde denn der Fehler angezeigt?
Allerdings wäre noch anmerken, dass natürlich auch mit "Bedingter Formatierung" (wie oben von Psycho Dad gezeigt) die Zeile "eingefettet" werden kann, da ja mit der dargestellten Formel immer der Inhalt der Spalte A geprüft wird und die Zeilennummer dabei keine Rolle spielt.

Grüße
bastla

P.S.: Zum Formatieren als Code nicht sondern <> verwenden.