I am new to VBA and I want to replicate below code in order to automate the process
=IF(A2="Male","M","F")
I have coded it as below to show the value in the 5th column ('F') offset of 'A'
Sub Gender1()
'
' Gender1 Macro
'
' =IF(A2="Male","M","F")
Dim rCell As Range
Dim rRng As Range
Set rRng = Range("A2", Range("A2").End(xlDown))
For Each rCell In rRng.Cells
If rCell.Value = "Male" Then
result = "M"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
ElseIf rCell.Value = "Female" Then
result = "F"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
Else
result = "NULL"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
End If
Next rCell
End Sub
I wanted to understand if the method is correct and should offset be used to display value or is there a better way to optimize the code and display value in the desired column.
I have to loop through 100 000 rows