kleur code

Status
Niet open voor verdere reacties.

sarges

Gebruiker
Lid geworden
11 okt 2008
Berichten
57
Beste mensen,

Zou iemand mij een nettere en snellere code kunnen geven voor het volgende?
Code:
    If cbo1 > 25 Then
        tables1.Cell(4, 5).Range.Font.Color = wdColorDarkRed
        tables1.Cell(4, 5).Range = Me("cbo1").Text & "°C"
    ElseIf cbo1 < 25 Then
        tables1.Cell(4, 5).Range.Font.Color = wdColorBlack
        tables1.Cell(4, 5).Range = Me("cbo1").Text & "°C"
    End If
        tables1.Cell(4, 7).Range = Me("cbo2").Text & "°C"
        tables1.Cell(4, 9).Range = Me("cbo3").Text & "°C"
    
    If cbo4 > 25 Then
        tables1.Cell(5, 5).Range.Font.Color = wdColorDarkRed
        tables1.Cell(5, 5).Range = Me("cbo4").Text & "°C"
    ElseIf cbo4 < 25 Then
        tables1.Cell(5, 5).Range.Font.Color = wdColorBlack
        tables1.Cell(5, 5).Range = Me("cbo4").Text & "°C"
    End If
        tables1.Cell(5, 7).Range = Me("cbo5").Text & "°C"
        tables1.Cell(5, 9).Range = Me("cbo6").Text & "°C"
'enz tot einde tabel van document, tabel kan bijvoorbeeld uit 20 regels bestaan.

Groet,

Serge
 
Dit is al wat korter:

Code:
For i = 1 To 40 Step 3
    If Me("cbo" & i) > 25 Then
        tables1.Cell(4, 5).Range.Font.Color = wdColorDarkRed
        tables1.Cell(4, 5).Range = Me("cbo" & i).text & "°C"
    Else
        tables1.Cell(4, 5).Range.Font.Color = wdColorBlack
        tables1.Cell(4, 5).Range = Me("cbo" & i).text & "°C"
    End If
    tables1.Cell(4, 7).Range = Me("cbo" & i + 1).text & "°C"
    tables1.Cell(4, 9).Range = Me("cbo" & i + 2).text & "°C"
Next i
 
Bedankt,

Ik heb geprobeerd om er weer verder mee te komen, maar lukt niet echt.
Werkt wel, maar moet veel beter kunnen.
Dit werk niet (kleur gaat niet goed)
Code:
For i = 1 To 3 Step 3
    If Me("cbo" & i) > 25 And Me("cbo" & i) < 59 Then
        tables1.Cell(4, 5).Range.Font.Color = wdColorDarkRed
        tables1.Cell(4, 5).Range = Me("cbo" & i).Text & "°C"
        tables1.Cell(4, 7).Range.Font.Color = wdColorDarkRed
        tables1.Cell(4, 7).Range = Me("cbo" & i + 1).Text & "°C"
        tables1.Cell(4, 9).Range.Font.Color = wdColorDarkRed
        tables1.Cell(4, 9).Range = Me("cbo" & i + 2).Text & "°C"
    Else
        tables1.Cell(4, 5).Range.Font.Color = wdColorBlack
        tables1.Cell(4, 5).Range = Me("cbo" & i).Text & "°C"
        tables1.Cell(4, 7).Range.Font.Color = wdColorBlack
        tables1.Cell(4, 7).Range = Me("cbo" & i + 1).Text & "°C"
        tables1.Cell(4, 9).Range.Font.Color = wdColorBlack
        tables1.Cell(4, 9).Range = Me("cbo" & i + 2).Text & "°C"
    End If
Next i
Dit werkt wel.
Code:
   For i = 1 To 3
    If Me("TextBox" & i) > 25 And Me("TextBox" & i).Text <= 59 Then
        tables1.Cell(4, i + 3).Range.Font.Color = wdColorRed
        tables1.Cell(4, i + 3).Range = Me("TextBox" & i).Text & "°C"
    Else
        tables1.Cell(4, i + 3).Range.Font.Color = wdColorBlack
        tables1.Cell(4, i + 3).Range = Me("TextBox" & i).Text & "°C"
    End If
Next i

For i = 4 To 6
    If Me("TextBox" & i) > 25 And Me("TextBox" & i).Text <= 59 Then
        tables1.Cell(5, i).Range.Font.Color = wdColorRed
        tables1.Cell(5, i).Range = Me("TextBox" & i).Text & "°C"
    Else
        tables1.Cell(5, i).Range.Font.Color = wdColorBlack
        tables1.Cell(5, i).Range = Me("TextBox" & i).Text & "°C"
    End If
Next i
For i = 7 To 9
    If Me("TextBox" & i) > 25 And Me("TextBox" & i).Text <= 59 Then
        tables1.Cell(6, i - 3).Range.Font.Color = wdColorRed
        tables1.Cell(6, i - 3).Range = Me("TextBox" & i).Text & "°C"
    Else
        tables1.Cell(6, i - 3).Range.Font.Color = wdColorBlack
        tables1.Cell(6, i - 3).Range = Me("TextBox" & i).Text & "°C"
    End If
Next i
 
Laatst bewerkt:
Iemand nog een mooie tip, werkt al beter maar nog lang niet het gewenste.
Code:
For n = 1 To 3
        tables1.Cell(4, n + 3).Range = Me("TextBox" & n).Text & "°C"

For i = 4 To 6
        tables1.Cell(5, n + 3).Range = Me("TextBox" & i).Text & "°C"
Next i
For i = 7 To 9
        tables1.Cell(6, n + 3).Range = Me("TextBox" & i).Text & "°C"
Next i
Next n

For r = 4 To 9
For t = 4 To 6
    If tables1.Cell(r, t).Range > "25" And tables1.Cell(r, t).Range < "59" Then
ActiveDocument.Tables(1).Cell(r, t).Range.Font.Color = wdColorRed
Else
ActiveDocument.Tables(1).Cell(r, t).Range.Font.Color = wdColorBlack
    End If
    Next t
Next r
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan