Last active
October 14, 2015 00:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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