I made the changes to the code below a few times. The same error still popped out. No idea where it went wrong. Need help with identifying the error.
I intend to base on categories stored in Column AB from Row 2 onwards to define division in Column AA.
For next is used to loop through the entire column from Row 2 until the last row.
I intend to base on categories stored in Column AB from Row 2 onwards to define division in Column AA.
For next is used to loop through the entire column from Row 2 until the last row.
VBA Code:
Sub Division()
Dim i As Long
Dim FinalRow As Long
ActiveWorkbook.Sheets("2020").Range("AB2").Select
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To FinalRow Step 1
Select Case Range("AB2:AB" & i).Value
Case "Hair Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Oral Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Health Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Personal Hygiene"
Range("AA2:AA" & i).Value = "PCD"
Case "Face Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Baby Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Body Moisturisers"
Range("AA2:AA" & i).Value = "PCD"
Case "Lip Care"
Range("AA2:AA" & i).Value = "PCD"
Case "Formulations"
Range("AA2:AA" & i).Value = "Pharma"
Case "Pure Herbs-Others"
Range("AA2:AA" & i).Value = "Pharma"
Case "Cats/Dogs"
Range("AA2:AA" & i).Value = "AHP"
Case "Poultry"
Range("AA2:AA" & i).Value = "AHP"
Case "Large Animals"
Range("AA2:AA" & i).Value = "AHP"
Case "#N/A"
Range("AA2:AA" & i).Value = "#N/A"
End Select
Next i
End Sub
Last edited by a moderator: