• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Macro vereenvoudigen

Status
Niet open voor verdere reacties.

wimix69

Gebruiker
Lid geworden
19 mrt 2011
Berichten
198
Hallo,

Ik gebruik een macro om te controleren of bepaalde velden zijn ingevuld. nu wil ik deze vereenvoudigen.


Code:
With Sheets("Kappenbril")
        If .Range("M203") = "Autograph_III_1.5" Then
            CheckKappenbril = LegeCel("AI218", "Kappenbril")
            CheckKappenbril = LegeCel("AI219", "Kappenbril")
            CheckKappenbril = LegeCel("AI220", "Kappenbril")
            CheckKappenbril = LegeCel("J214", "Kappenbril")
        End If
    End With
    With Sheets("Kappenbril")
        If .Range("M203") = "Autograph_III_1.6" Then
            CheckKappenbril = LegeCel("AI218", "Kappenbril")
            CheckKappenbril = LegeCel("AI219", "Kappenbril")
            CheckKappenbril = LegeCel("AI220", "Kappenbril")
            CheckKappenbril = LegeCel("J214", "Kappenbril")
        End If
    End With
    With Sheets("Kappenbril")
        If .Range("M203") = "Autograph_III_1.67" Then
            CheckKappenbril = LegeCel("AI218", "Kappenbril")
            CheckKappenbril = LegeCel("AI219", "Kappenbril")
            CheckKappenbril = LegeCel("AI220", "Kappenbril")
            CheckKappenbril = LegeCel("J214", "Kappenbril")
        End If
    End With
    With Sheets("Kappenbril")
        If .Range("M203") = "Autograph_III_1.74" Then
            CheckKappenbril = LegeCel("AI218", "Kappenbril")
            CheckKappenbril = LegeCel("AI219", "Kappenbril")
            CheckKappenbril = LegeCel("AI220", "Kappenbril")
            CheckKappenbril = LegeCel("J214", "Kappenbril")
        End If
    End With


Dit werkt niet, hoe krijg ik hem wel werkend

Code:
 If .Range("M203") = "Autograph_III_1.5",  If .Range("M203") = "Autograph_III_1.6", If .Range("M203") = "Autograph_III_1.67", If .Range("M203") = "Autograph_III_1.74" Then
            CheckKappenbril = LegeCel("AI218", "Kappenbril")
            CheckKappenbril = LegeCel("AI219", "Kappenbril")
            CheckKappenbril = LegeCel("AI220", "Kappenbril")
            CheckKappenbril = LegeCel("J214", "Kappenbril")
        End If
    End With
 
Zonder dat je een voorbeeld document hebt geplaatst, zoiets:
Code:
CheckM203 = "Autograph_III_1.5|Autograph_III_1.6|Autograph_III_1.67|Autograph_III_1.74"
If Range("M203") <> "" And InStr(1, CheckM203, Range("M203")) > 0 Then
    CheckKappenbril = LegeCel("AI218", "Kappenbril")
    CheckKappenbril = LegeCel("AI219", "Kappenbril")
    CheckKappenbril = LegeCel("AI220", "Kappenbril")
    CheckKappenbril = LegeCel("J214", "Kappenbril")
End If
 
Rare constructie als je het mij vraagt.

Waarom krijgt die 'CheckKappenbril' 4 keer een andere waarde?
Code:
    CheckKappenbril = LegeCel("AI218", "Kappenbril")
    CheckKappenbril = LegeCel("AI219", "Kappenbril")
    CheckKappenbril = LegeCel("AI220", "Kappenbril")
[COLOR=#ff0000]    CheckKappenbril = LegeCel("J214", "Kappenbril")[/COLOR]

Het krijgt alleen maar de waarde van de laatste = LegeCel("J214", "Kappenbril")
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan