Use find/replace in the worksheet via Surfer automation

The find & replace function can be invaluable in certain workflows.  For example, you may want to change the null value in a dataset from -999 to 0.  The script below shows how to automate this function in Surfer's worksheet.

To run this script:

  1. Copy the script below, or download the attached BAS file: Replace.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.


'Replace.bas shows how to use the Edit | Replace function in automation
'to replace a value in the worksheet with another value.

Sub Main
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'Open the worksheet document
	Set Wks = SurferApp.Documents.Open(SurferApp.Path+"\Samples\demogrid.dat")

'Specify the worksheet range
    Set WksRange = Wks.Columns(Col1:=1, Col2:=2)

'Replace "4" with the text "test"
	Set After = Wks.Range(1, "A", 1, "A")      'First cell
	WksRange.Replace(TargetStr:="4", ReplaceStr:="test", Current:=After, Scope:=wksFindScopeEntire, Method:=wksFindPhrase, ReplaceAll:=True)
End Sub


Updated November 2021

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.