Forum Discussion
Bkkendig
May 25, 2023Copper Contributor
Excel Script to Remove Carriage Returns
I am trying to write an excel online script to remove carriage returns. Writing a macro to do this is in the desktop version of excel is easy via "cntl+j" using the replace drop down. However, I find that "cntl+j" is not working for me in the excel online environment. Any suggestions for how to write a script to remove carriage returns in excel online??
As far as I can see, using SQL Management Studio you are connecting to a server name that has one R letter but in Excel, you have two R letters in TIRREL.
If you are connecting fine from SQL Management Studio, then your hostname only contains one R.
4 Replies
Sort By
- NikolinoDEGold Contributor
To remove carriage returns in Excel Online using Office Scripts, you can utilize the replaceAll method of the Range object.
Here's an example script that removes carriage returns from a specific range of cells:
function main(workbook: ExcelScript.Workbook) { let sheet = workbook.getActiveWorksheet(); let range = sheet.getRange("A1:A10"); // Specify the range where your data is located // Replace carriage returns with an empty string range.replaceAll("\r", ""); // Save the changes workbook.save(); }
To use this script:
To use this script:
- Open the Excel Online workbook where you want to remove carriage returns.
- Click on the "Automate" tab in the ribbon.
- Click on "Script Lab" to open the Office Scripts editor.
- In the editor, create a new script and paste the provided code.
- Adjust the range in the getRange method to match the actual range of your data.
- Click the "Run" button to execute the script.
The script will replace all carriage returns (\r) with an empty string in the specified range. Make sure to save the changes after running the script.
- BkkendigCopper ContributorWorks great. Thanks!!
- NikolinoDEGold ContributorI am glad that I could help you with your project.
I wish you continued success with Excel!