I have a sheet where I have 5 columns
Row OM MA HP D
----------------------------------
1 212 5454 4787 OM
----------------------------------
2 212 5454 4787 MA
----------------------------------
3 212 5454 4787 OM
---------------------------------
4 212 5454 4787 HP
--------------------------------
I want to update OM, MA and HP based on the value in D. So if D=OM I want to make the columns other than OM to be equal to zero.
I have already written the script but I want to learn how to change this script so that the range that the script chooses is dynamic and not specified beforehand and can be updated based on the data we have.
Can anyone help me please?
Thanks in advance,
Here's the script:
Public Sub DataClear()
Dim rgdata As Range
Dim i As Integer
Worksheets("Data").Activate
Set rgdata = Range("A1:E10")
For i = 0 To rgdata.Rows.Count
If rgdata.Cells(i + 1, "E").Value = "MO" Then
rgdata.Cells(i + 1, "C").Value = "0"
rgdata.Cells(i + 1, "D").Value = "0"
ElseIf rgdata.Cells(i + 1, "E").Value = "MA" Then
rgdata.Cells(i + 1, "B").Value = "0"
rgdata.Cells(i + 1, "D").Value = "0"
ElseIf rgdata.Cells(i + 1, "E").Value = "HP" Then
rgdata.Cells(i + 1, "B").Value = "0"
rgdata.Cells(i + 1, "C").Value = "0"
End If
Next i
End Sub