How can I use a Surfer script to clear data in a column if the value is the same as another cell's value?

This article contains a sample script for deleting data in a particular column in the worksheet if it is equal to the value in another cell.

To run this script:

  1. Copy the script below, or download the attached BAS file: WorksheetComparison.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\GoldenSoftware\Surfer 16.
  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.   

'Compares values in a column to another cell value.
'If the values match, it clears the duplicate data.
Sub Main

'Initialize Surfer
 	Dim SurferApp, Wks, WksRange, WksRange2 As Object
 	Set SurferApp = CreateObject("Surfer.Application")
 	SurferApp.Visible = True

'Prompt user for a DAT file
        filename$ = GetFilePath(,"dat")

'If the file name isn't empty, open it in the worksheet
        If filename$ <> "" Then
          Set Wks = SurferApp.Documents.Open(filename$)
   	End If

'Specify which cell to compare to (B2) and set it to variable (Time).
	Dim Time As Variant
	Set Time = Wks.Cells("B2")

'Sets the WksRange variable to the entire worksheet (Cols A-C)
	Set WksRange = Wks.Columns(Col1:=1, Col2:=3)

'Clears the data in selected column (B) if it is equal to the Time variable
	For i=3 To Wks.UsedRange.LastRow
	  If WksRange.Cells("B"+Format (i)) = Time Then
	    WksRange.Cells("B"+Format (i)).Clear
	  End If
	Next i

'Saves the data file with Time added to the name
	If InStrRev(filename$,".")>1 Then filename$ = Left(filename$,InStrRev(filename$,".")-1)

End Sub


Updated November 7, 2018

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.