Category Archives: MS Excel Spreadsheet

Macro – Adding double quotes for all values in a column in Excel Spreadsheet

Scenario:

I have Excel spreadsheet file, which contains one or more columns and rows.  I want to select a particular column, so that all values in that column should be placed within double  quotes.  That is, it the value is xyz, it should become “xyz”.    This should happen even when I select a particular cell.  When I select a particular cell in a column, the values in the whole column should be updated in such a way that, the values should be enclosed within double quotes.

Macro for the above scenario is,

Sub doublequotes()

Dim tmp_jsn
Dim iLastRow As Long
Dim i As Long
With ActiveCell
iLastRow = Cells(Rows.Count, .Column).End(xlUp).Row
For i = 1 To iLastRow

tmp_jsn = Cells(i, .Column).Value

tmp_jsn = “””” + tmp_jsn + “”””
Cells(i, .Column).Value = tmp_jsn

Next i

End With
End Sub
Advertisements