user3075601
user3075601

Reputation: 134

Excel: Remove everything after ? in a url

I already searched for formulas or add ins online but can't seem to find any formula for this.

I was wondering if I can remove everything after a question mark in a URL?

http://www.site.com/index.php?98943j%klr

to

http://www.site.com/index.php

Thanks!

Upvotes: 7

Views: 10352

Answers (4)

JohnP2
JohnP2

Reputation: 2177

For a manual way, use find and replace: find: ~?* replace with: (nothing)

A comment above has the best answer: LEFT(A1,FIND("?",A1)-1) with the -1 included.

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172468

You may try something like this:

=LEFT(A1,FIND("?",A1))

Here A1 is your url

Upvotes: 3

brettdj
brettdj

Reputation: 55682

Try

=IF(LEN(SUBSTITUTE(A1,"?",""))=LEN(A1),A1,LEFT(A1,FIND("?",A1)-1))

to

  • Cater for the ? not appearing in A1 without raising an error
  • Properly truncating the string to http://www.site.com/index.php .... your accepted answer doesnt adjust for the position of ? and it will return http://www.site.com/index.php?

Upvotes: 12

Netloh
Netloh

Reputation: 4378

If you want to return another hyperlink, but only cosisting of everything before the question mark, you could use the following formula, having you URL in cell A1.

=HYPERLINK(LEFT(A1,FIND("?",A1,1)-1))

Upvotes: 3

Related Questions