How can I use a Surfer script to delete data in a row if a cell in a particular column meets certain criteria?

This article contains a sample script for deleting a row of data in the worksheet if a cell in a particular column meets specified criteria.

To run this script:

  1. Copy the script below, or download the attached BAS file: WorksheetDeleteRow.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. Change the values in the User-defined variables section as desired.
  7. Click Script | Run to run the script.  

'Deletes all rows of data if contents in specified column meet specified criteria.
Sub Main

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

'User-defined variables
'Criteria value for comparison with values in designated column
    crit_val = 300

'Column to compare the criteria value to (1=A, 2=B, etc)
    crit_col = 3

'Prompt use for 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

'Sets the WksRange variable to all rows in designated column
    Set WksRange = Wks.Columns(Col1:=crit_col)

'Deletes the entire row if data in designated column is greater than the criteria value
    For i=2 To Wks.UsedRange.LastRow
  	If WksRange.Cells(i,1) > crit_val Then
  	End If
    Next i

End Sub


Updated November 8, 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.