Forum Discussion
anniethoang
Aug 01, 2023Copper Contributor
Automatic content fill-in in a new column
Hi - I need help categorizing content/ auto-fill from the column A to column B. For example, all the cells in column A with "Argentina" automatically abbreviates to "AR" in corresponding row in colum...
OliverScheurich
Aug 01, 2023Gold Contributor
Sub abbreviation()
Dim i, j As Long
j = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To j
Select Case Cells(i, 1).Value
Case Is = "argentina"
Cells(i, 2).Value = "AR"
Case Is = "aruba"
Cells(i, 2).Value = "AA"
Case Is = "belgium"
Cells(i, 2).Value = "BE"
End Select
Next i
End Sub
Maybe with these lines of code. In the attached file you can run the macro to fill in the abbreviations.
- anniethoangAug 02, 2023Copper ContributorWhere would I fill in code in on Excel?
- OliverScheurichAug 02, 2023Gold Contributor
In the worksheet you can press the keys ALT+F11 to open the VBA Editor. Then select Insert -> Module to open a new module. Now you can paste the suggested code in the module. Then you have to save the workbook as a macro-enabled workbook in order to save the code.
- anniethoangAug 02, 2023Copper Contributoris there a simpler way with no code?
- OliverScheurichAug 02, 2023Gold Contributor
You could apply INDEX and MATCH along with a reference table. INDEX and MATCH with reference table should be simpler than VBA. However the formula has to be draged down which could slow down the file.