Skip to content

Instantly share code, notes, and snippets.

@mattcan
Last active October 14, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcan/4278525 to your computer and use it in GitHub Desktop.
Save mattcan/4278525 to your computer and use it in GitHub Desktop.
Takes the name of a field in a string, the character after the value, and returns the value in an adjacent column. I used this to parse a few hundred URLs for the value of the username.
Sub FindValue()
Dim ws As Excel.Worksheet
Set ws = ActiveSheet
Dim i As Integer, lastRow As Integer
lastRow = 328
Dim fromCol As String, toCol As String, field As String, delim As String
fromCol = "C"
toCol = "D"
field = "username="
delim = "&"
Dim fieldPos As Integer, delimPos As Integer, startPos As Integer, searchText As String
For i = 2 To lastRow
searchText = ws.Range(fromCol & i).Value
fieldPos = InStr(1, searchText, field)
delimPos = InStr(fieldPos, searchText, delim)
startPos = fieldPos + Len(field)
ws.Range(toCol & i).Value = Mid(searchText, startPos, delimPos - startPos)
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment