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:
- Copy the script below, or download the attached BAS file: WorksheetComparison.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press DELETE.
- 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.
- Click Script | Run to run the script.
'======================================== 'WorksheetComparison.bas '======================================== '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) Wks.SaveAs(FileName:=filename$+Time+".txt") End Sub
Updated November 7, 2018
Comments
0 comments
Please sign in to leave a comment.