Parse variables from URL with formula after pasting in Excel

0

I often have long URL's that have ampersand delimited variables at the end, and I would like to be able to simply paste the whole URL and have all the variables populate the fields below in the same column. Here is an example:

http://test.com/api/get?action=add&stage=initial&name=bob&lastname=smith&etc....

So I would like to be able to paste this in to A1, and have the variables and their values appear in the cells below like this:

http://test.com/api/get
action=add
stage=initial
name=bob
lastname=smith

The other issue is that after the "get" there is a question mark (?) which starts the variables, so I need the info after the question mark considered a variable as well. It would be great if I could place some kind of formula in the A1 cell that would handle this. Can anyone help with this?

Pleading and Grateful

Posted 2015-03-11T18:03:39.850

Reputation: 1

Answers

2

With a URL in cell A1, in A2 enter:

=TRIM(MID(SUBSTITUTE($A$1,"&",REPT(" ",999)),ROWS($1:1)*999-998,999))

and copy down:

enter image description here

Gary's Student

Posted 2015-03-11T18:03:39.850

Reputation: 15 540

Excellent! What a wonderful job Gary's Student! Now is there a way to have it also take the "action=add" and list it as a separate cell? Keep in mind that these variables after the get? can and do change at any time, so all this has to be done by identifying them by the delimiters "?" and "&". Thanks so much! – Pleading and Grateful – 2015-03-11T20:15:51.223

@PleadingandGrateful Just add another substitute function around the current one to treat the "?" as a delimiter too. =TRIM(MID(SUBSTITUTE(SUBSTITUTE($A$1,"&",REPT(" ",999)),"?",REPT(" ",999)),ROWS($1:1)*999-998,999)) – Mark Balhoff – 2015-03-11T20:51:00.060

@PleadingandGrateful Good job! .............. A simple mod to the formula will allow it to be copied across a row rather than down a column. – Gary's Student – 2015-03-11T21:11:18.210

1for anyone wondering COLUMNS($A$1:B$1) instead of ROWS($1:1) is what makes it go from row-based to column-based – MrMesees – 2018-12-07T08:11:05.010