Macro to create hyperlink

luckyprime

New Member
Joined
May 24, 2011
Messages
1
Hello mr excel.

I have seen various post and fantastic answers to critical problems, solved by forum members

I have an problem with creating hyperlink i.e macro to create hyperlink

i requirement is that.... i want to click a range of data and create a hyperlink for each of these cells,,,,, After clicking the data of the cell should be in the search box of website like wikisearch or any other site... where can we search that data...


results are likely to--- click on hyperlink----will open target site----with cell data in search box ... search performed.... with single click on cell to create a macro for that


i am unable to link the data to search box of webpage.... in macro.....

Pls help
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If I understand you correctly, this code might do the trick. Place it in the code module for the worksheet where you want it to operate.
Code:
Option Explicit
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
  Dim oCell As Range
 
  If Target.Column <> [COLOR=red][B]1[/B][/COLOR] Then Exit Sub
  If Target.Columns.Count > 1 Then Exit Sub
  If Target.Cells.Count = Rows.Count Then Exit Sub
 
  For Each oCell In Selection
    If Not IsEmpty(oCell) Then
      ActiveSheet.Hyperlinks.Add Anchor:=oCell, TextToDisplay:=oCell.Value, _
          Address:="[URL]http://en.wikipedia.org/w/index.php?search[/URL]=" & Replace(oCell.Value, " ", "+")
    End If

  Next oCell
 
End Sub
When you select any cell in column 1 (column A), whatever text is in the cell will be converted into a hyperlink. Then you just need to click the hyperlink to open the Wiki page.

You can modify the code to be effective in a different column - specified by the bit in red - and you can change the URL to use whatever search engine you wish. For example to use Google you would code:-
Code:
Address:="http://www.google.com/search?q=" & Replace(Target.Value, " ", "+")
Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top