Search code examples
excelvbarangecomparison

Using VBA to Convert Integers into Text


I am trying to write a Vba that will take the numbers in one column and convert the numbers to text in another column.

For example:

4 will be “quarterly”, 1 will be “annually” and 12 will be “monthly”.

This is what I wrote but only the last line is working.

Sub Convert ()

    Range("J6:J1447").Formula = "If(I6:I299=1, (""Annually""), """")"

    Range("J6:J1447").Formula = "=If(I6:I299=2, (""Semi-Annually""), """")"

    Range("J6:J1447").Formula = "=If(I6:I299=4, (""Quarterly""), """")"

    Range("J6:J1447").Formula = "=If(I6:I299=12, (""Monthly""), """")"

End Sub

Solution

  • Range("J6:J1447").formular1c1-"=if(rc[-1]=1,""ANNUALLY"",if(rc[-1]=2,""SEMI-ANNUALLY"",if(rc[-1]=4,""QUARTERLY"",if(rc[-1]=12,""MONTHLY"",""""))))"
    

    You could also do an Last row option to not limit yourself with your range.