Antwoord van een "ALS" formule in een string (vba)

Status
Niet open voor verdere reacties.

MEradus

Gebruiker
Lid geworden
25 nov 2012
Berichten
287
Hoi,

Ik heb onderstaande formule, maar hij werkt niet zoals ik wil.

Het is de bedoeling dat hij in dezelfde cel deze berekening zet en dat de 'uitkomst' dan uiteindelijk in deze cel komt.
Als ik beide formules apart doe in Excel, dan krijg ik netjes het antwoord.
Maar als ik het op onderstaande doe krijg ik "onwaar / onwaar".

Wie kan mij helpen?

Alvast bedankt.

P.s. Ik hoop dat het op deze manier kan, een voorbeeld bestand heb ik (nog) niet.

Code:
Range("J7:J10000").Select
Dim c As Range
Set c = Cells.Find("PrioRit", ActiveCell, xlValues, xlWhole, xlByRows, xlNext, True)
If Not c Is Nothing Then
Do
Dim ust As String
Dim ist As String
ist = ActiveCell.FormulaR1C1 = "=IF(RC[-6]>RC[-7],""In NoK"",""In OK"")"
ust = ActiveCell.FormulaR1C1 = "=IF(RC[-2]>RC[-1],""Uit NoK"",""Uit OK"")"
c.Resize().FormulaR1C1 = ist & " / " & ust
Set c = Cells.FindNext(c)
Loop While Not c Is Nothing
If c Is Nothing Then
Exit Sub
End If
End If
End Sub
 
Doe er eens een voorbeeldje met wat gegevens bij; dat kijkt een stuk makkelijker. Hoeven er uitaard geen duizenden te zijn :).
 
MEradus,

Ik heb je VBA wat herschreven, volgens mij moet dit wel werken.

Code:
Sub test()

Dim c As Range
Dim ust As String
Dim ist As String
Range("J7").Select
Set c = Range("J7:J10000").Find("PrioRit", ActiveCell, xlValues, xlWhole, xlByRows, xlNext, True)
If Not c Is Nothing Then
    Do
        ist = IIf(c.Offset(0, -6) > c.Offset(0, -7), "In NoK", "In OK")
        ust = IIf(c.Offset(0, -2) > c.Offset(0, -1), "Uit NoK", "Uit OK")
        
        c.Value = ist & " / " & ust
        Set c = Cells.FindNext(c)
    Loop While Not c Is Nothing
    If c Is Nothing Then
        Exit Sub
    End If
End If

End Sub

Veel Succes
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan