The following macro assumes that the worksheet containing the data is the active sheet, and that the data starts at cell A1...
VBA Code:
Sub AddQuotes()Dim lastRow AsLong
lastRow = Cells(Rows.Count,"A").End(xlUp).Row
Dim lastCol AsLong
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Dim rng As Range
Set rng = Range("A1", Cells(lastRow, lastCol))Dim cell As Range
ForEach cell In rng
cell.Value =""""& cell.Value &""""Next cell
EndSub
By the way, I would suggest that you update your profile to include the version of Excel you're using, as it may help in future in providing the most efficient solution.
If the data in the worksheet goes beyond the row and column limits of A1, then the range defined by Domenic's line of code may not include all the cells with data in the worksheet.
To ensure that all cells with data are included in the range, you can use the UsedRange property of the worksheet, as shown in below code.
I'm not a VBA expert, so try this in a copy of your workbook.
VBA Code:
Sub AddQuotesToUsedRange()Dim cell As Range
Dim myRange As Range
Set myRange = ActiveSheet.UsedRange
ForEach cell In myRange
IfNot IsEmpty(cell.Value)Then
cell.Value = Chr(34)& cell.Value & Chr(34)EndIfNext cell
EndSub
Alternatively, you can use the find function to define the last row and column.
We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel
Which adblocker are you using?
Disable AdBlock
Follow these easy steps to disable AdBlock
1)Click on the icon in the browser’s toolbar. 2)Click on the icon in the browser’s toolbar. 2)Click on the "Pause on this site" option.
Go back
Disable AdBlock Plus
Follow these easy steps to disable AdBlock Plus
1)Click on the icon in the browser’s toolbar. 2)Click on the toggle to disable it for "mrexcel.com".
Go back
Disable uBlock Origin
Follow these easy steps to disable uBlock Origin
1)Click on the icon in the browser’s toolbar. 2)Click on the "Power" button. 3)Click on the "Refresh" button.
Go back
Disable uBlock
Follow these easy steps to disable uBlock
1)Click on the icon in the browser’s toolbar. 2)Click on the "Power" button. 3)Click on the "Refresh" button.