Friday, April 6, 2012

Extracting a subset of records in ArcMap 10

If you are looking to subsample your data by extracting a set number of records (i.e., every sixth record), use the script below in the field calculator of ArcMap 10.

Pre-Logic Script Code:
P=[ID]
i=Int(p/6)-Int((p-1)/6)

[name of field]=
i

The example above will extract every sixth record.

Thursday, April 5, 2012

In String for Excel

For some reason, Excel doesn't have a built-in function to query whether a string contains a specified second string. Luckily, the joys of VB allow us to do so.

In Excel, under the Developer tab, click "Visual Basic." In the left-hand pane, right-click "VBAProject ()" > Insert > Module. Paste the below snippet into the main pane and save. Now you can call this function into Excel just as you would any other.

~~~
Function InstrE(start As Integer, examine As String, lookFor As String) As Integer

InstrE = InStr(start, examine, lookFor)

End Function
~~~