All templates
Excel AutomationBeginner
Search and Replace Excel Values
Robomotion•Updated 6 months ago

Overview
Performs a find-and-replace across an Excel worksheet and saves the result. Handy for bulk corrections or masking sensitive fields.
Search and Replace Excel Values
Finding and replacing values while working with big Excel spreadsheets can be a time-consuming and tiring task. Simplify Excel handling and decrease searching time using Robomotion's Excel nodes.
What Search and Replace Excel Values can do
- Build Default Path (
Core.Programming.Function) — setsmsg.fixtures_dirandmsg.sample_xlsx(…/fixtures/sample.xlsx). - Four Input Dialogs (
Core.Dialog.InputBox, all titledSearch and replace Excel values):Text to find:(defaultIstanbul) →msg.text_to_find.Text to replace with:(defaultIzmir) →msg.new_text.- File path (default
msg.sample_xlsx) →msg.selected_file. - Mode
all/first(defaultall) →msg.rename_function.
- Validate (
Core.Programming.Function,outputs: 2) — requires a non-emptymsg.text_to_findand an.xls*/.csvfile; normalisesmsg.rename_functiontofirstorall; otherwiseCore.Flow.Stop. - Open Excel (
Robomotion.MicrosoftExcel.OpenExcel,optVisible: true) →msg.excel_app_id. - Search (
Robomotion.MicrosoftExcel.SearchSheet,sheetSelection: Active-Sheet,searchTerm: msg.text_to_find) →msg.found_cells. - Pick Cells To Replace (
Core.Programming.Function) —msg.cells_to_replaceis the full array or just the first match based onmsg.rename_function. - Loop via
Core.Flow.Label+Core.Programming.ForEachovermsg.cells_to_replace→msg.current_cell:- Extract Cell Address (
Core.Programming.Function) normalises the item (string,.address,.Cell, or{column,row}) intomsg.cell_address. - Replace Value (
Robomotion.MicrosoftExcel.SetCellValue,mod1: string,continueOnError: true) writesmsg.new_textatmsg.cell_address. Core.Flow.GoToback to the loop label.
- Extract Cell Address (
- On loop exit: Save (
Robomotion.MicrosoftExcel.SaveExcel), Close (Robomotion.MicrosoftExcel.CloseExcel), then aDone!info dialog andCore.Flow.Stop.
Behind the scenes
SearchSheetruns withsheetSelection: Active-Sheet, so the search is limited to whichever sheet is active when Excel opens the file.Replace ValueusescontinueOnError: trueso a single protected/locked cell doesn't abort the whole loop.Extract Cell Addresshandles multiple shapes ofSearchSheetoutput because the package has returned different formats across versions; normalising to a plainA1-style string keepsSetCellValuehappy.- Replacement writes the whole
msg.new_textas a string (mod1: string) — partial, case-sensitive matching is not performed; each hit cell is fully overwritten.