Follow

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 15\Scripter.
  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.  

*********

'WorksheetDeleteRow.bas deletes all rows of data if contents in specified
'column meet specified criteria. In this example, rows are deleted if
'data in Column C is greater than 70.

'======================================

Sub Main

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

 	Dim Wks As Object
    filename$ = GetFilePath(,"dat")
    If filename$ <> "" Then
    Set Wks = SurferApp.Documents.Open(filename$)
   	End If

'Sets the WksRange variable to all rows in Column C
 	Dim WksRange As Object
	Set WksRange = Wks.Columns(Col1:=3)

'Deletes the entire row if data in column C is greater than 70
		For i=2 To Wks.UsedRange.LastRow
  			If WksRange.Cells(i,1) > 70 Then
  			WksRange.Cells(i,1).Delete(Direction:=wksDeleteRows)
  			i=i-1
  			End If
		Next i

End Sub

 

Updated September 14, 2017

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

0 Comments

Please sign in to leave a comment.