VBA If
13.05.2020 13:24:31
Gregor
habe was im web gefunden, was für mich passen könnte.
Möchte aber zwei Zellen vergleichen.
Wenn in diesen der Wert steht dann schreibe in Zelle X100 folgenden Wert.
Also die Zeile:
marks = rg.Cells(i, 3).Value
mit zwei Zellen
' Description: The same as the ElseDemo
Sub above except this writes out
' the results to column E in the table.
' Worksheet: Marks
' https://excelmacromastery.com/vba-if
Sub ElseDemo2()
' Get the data range
Dim rg As Range
Set rg = shMarks.Range("A1").CurrentRegion
' Clear existing classifications
rg.Columns(5).Offset(1).Cells.ClearContents
Dim i As Long, marks As Long, class As String
' Go through the marks columns
For i = 2 To rg.Rows.Count
' Get the marks
marks = rg.Cells(i, 3).Value
' check the marks using if and ElseIf
If marks >= 85 Then
class = "High Destinction"
ElseIf marks >= 75 Then
class = "Destinction"
ElseIf marks >= 55 Then
class = "Credit"
ElseIf marks >= 40 Then
class = "Pass"
Else
' All other marks
class = "Fail"
End If
rg.Cells(i, 5).Value = class
Next i
End Sub