I am new to VBA and have written a code to basically go through a column of data and based on the contents fill another column with abbreviations. I was wondering if there was a simpler method of doing this same task. Also, on the last line I filled in the values using the offset function, but I would really prefer to have it set to column W; I just didn't know how to make it cycle through in that way. Any help or suggestions would be appreciated. Thank you.
Sub Motor_Enclosure()
Dim Mtr_Enclosure As String
Dim Enclosure As String
Dim LastRow As Integer
Dim Rng As Range
Dim i As Integer
'Finds the last row in the worksheet
LastRow = ActiveWorkbook.Sheets("Data").Cells(Rows.Count, "M").End(xlUp).Row
'Loops through cells in colum M from M2 to last cell with value
For Each Rng In ActiveWorkbook.Sheets("Data").Range("M2:M" & LastRow)
'Assigns value of current cell to variable
Mtr_Enclosure = Rng.Value
'Checks value of cell and assigns abbreviation to Enclosure variable
Select Case Mtr_Enclosure
Case "2 SPEED ODP"
Enclosure = "ODP"
Case "2 SPEED TEFC"
Enclosure = "TEFC"
Case "EXPLOSION PROOF"
Enclosure = "EXP"
Case "OPEN DRIP PROOF"
Enclosure = "ODP"
Case "TOTALLY ENCLOSED AIR OVER"
Enclosure = "TEAO"
Case "TOTALLY ENCLOSED FAN COOLED"
Enclosure = "TEFC"
Case Else
Enclosure = ""
End Select
Rng.Offset(0, 10) = Enclosure
Next Rng
End Sub
Bookmarks