Follow

How can I use a Surfer script to delete 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 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.   

*********

'WorksheetComparison.bas will compare values in a column to another cell value
'if the values match, then you can clear or delete the column data.

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

Sub Main

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

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

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

'Sets the WksRange variable to all rows in the worksheet (Columns A-C in this example)
 		Dim WksRange As Object
		Set WksRange = Wks.Columns(Col1:=1, Col2:=3)

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

'Deletes the data in selected column (C) if it is equal to Time
	'	For i=3 To Wks.UsedRange.LastRow
  	'	If WksRange.Cells("C"+Format (i)) = Time Then
  	'		WksRange.Cells("C"+Format (i)).Delete(Direction:=wksDeleteUp)
  	'		i=i-1
  	'		End If
	'	Next i

'Saves the data file with Time in name
		Wks.SaveAs(FileName:="C:\temp\"+Time+".txt")

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.