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:
- Copy the script below, or download the attached BAS file: WorksheetDeleteRow.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.
- Change the values in the User-defined variables section as desired.
- Click Script | Run to run the script.
'====================================== 'WorksheetDeleteRow.bas '====================================== '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 WksRange.Cells(i,1).Delete(Direction:=wksDeleteRows) i=i-1 End If Next i End Sub
Updated November 8, 2018
Comments
0 comments
Please sign in to leave a comment.