How do I convert a column of text URLs into active hyperlinks in Excel? - excel-2007

I have a column in excel, wherein I have all the website url values. My question is I want to turn the url values to active links. There are about 200 entries in that column with different urls in all cells. Is there a way I can create active hyperlinks to all the cells without writing a macro.

If you don't want to make a macro and as long as you don't mind an additional column, then just create a new column alongside your column of URLs.
In the new column type in the formula =HYPERLINK(A1) (replacing A1 with whatever cell you are interested in). Then copy the formula down the rest of the 200 entries.
NOTE: This solution does not work if the cell A1 contains a string longer than 255 characters. It results in a #VALUE! error

Create the macro as here:
On the Tools menu in Microsoft Excel, point to Macro, and then click Visual Basic Editor.
On the Insert menu, click Module.
Copy and paste this code into the code window of the module.
It will automatically name itself HyperAdd.
Sub HyperAdd()
'Converts each text hyperlink selected into a working hyperlink
For Each xCell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell
End Sub
When you're finished pasting your macro, click Close and Return to Microsoft Excel on the File menu.
Then select the required cells and click macro and click run.
NOTE Do NOT select the whole column! Select ONLY the cells you wish to be changed to clickable links else you will end up in a neverending loop and have to restart Excel!
Done!

Pretty easy way for rather short lists:
Double click on the box where the url is
Enter
You have your link ;)

Here's a way I found. I'm on a Mac using Excel 2011.
If column B had the text values you want to be hyperlinks, put this formula in the cell C1 (or D1 or whatever as long as it's a free column): =HYPERLINK(B1,B1)
This will insert a hyperlink with the location as the link text and the "friendly name" as the link text. If you have another column that has a friendly name for each link, you could use that too.
Then, you could hide the text column if you didn't want to see it.
If you have a list of IDs of something, and the urls were all http://website.com/folder/ID, such as:
A1 | B1
101 | http://website.com/folder/101
102 | http://website.com/folder/102
103 | http://website.com/folder/103
104 | http://website.com/folder/104
you could use something like =HYPERLINK("http://website.com/folder/"&A1,A1) and you wouldn't need the list of urls. That was my situation and worked nicely.
According to this post: http://excelhints.com/2007/06/12/hyperlink-formula-in-excel/ this method will work in Excel 2007 as well.

OK, here's a hokey solution, but I just can't figure out how to get Excel to evaluate a column of URLs as hyperlinks in bulk.
Create a formula, ="=hyperlink(""" & A1 & """)"
Drag down
Copy new formula column
Paste Special Values-only over the original column
Highlight column, click Ctrl-H (to replace), finding and replacing = with = (somehow forces re-evaluation of cells).
Cells should now be clickable as hyperlinks. If you want the blue/underline style, then just highlight all cells and choose the Hyperlink style.
The hyperlink style alone won't convert to clickable links, and the "Insert Hyperlink" dialog can't seem to use the text as the address for a bunch of cells in bulk. Aside from that, F2 and Enter through all cells would do it, but that's tedious for a lot of cells.

If adding an extra column with the hyperlinks is not an option,
the alternative is to use an external editor to enclose your hyperlink into =hyperlink(" and "), in order to obtain =hyperlink("originalCellContent")
If you have Notepad++, this is a recipe you can use to perform this operation semi-automatically:
Copy the column of addresses to Notepad++
Keeping ALT-SHIFT pressed, extended your cursor from the top left corner to the bottom left corner, and type =hyperlink(". This adds =hyperlink(" at the beginning of each entry.
Open "Replace" menu (Ctrl-H), activate regular expressions (ALT-G), and replace $ (end of line) with "\). This adds a closed quote and a closed parenthesis (which needs to be escaped with \ when regular expressions are activated) at the end of each line.
Paste back the data in Excel. In practice, just copy the data and select the first cell of the column where you want the data to end up.

I shocked Excel didn't do this automatically so here is my solution I hope would be useful for others,
Copy the whole column to clipboard
Open this on your Chrome or Firefox
data:text/html,<button onclick="document.write(document.body.querySelector('textarea').value.split('\n').map(x => '<a href=\'' + x + '\'>' + x + '</a>').join('<br>'))">Linkify</button><br><textarea></textarea>
Paste the column on the page you just opened on the browser and press "Linkify"
Copy the result from the tab to the the column on Excel
Instead step two, you can use the below page, first, click on "Run code snippet" then paste the column on it
<button onclick="document.write(document.body.querySelector('textarea').value.split('\n').map(x => '<a href=\'' + x + '\'>' + x + '</a>').join('<br>'))">Linkify</button><br><textarea></textarea>

This method works for me using the hyperlink function:
=HYPERLINK("http://"&B10,B10)
Where B10 is the cell containing the text version of the URL (in this example).

With Excel 2007 on Windows, I found these steps simplest;
Select cells with the non-active URLs
Copy
Paste as hyperlink

Create a temporary new column of hyperlinks using formula =HYPERLINK()
Copy that column into Microsoft Word (copy to clipboard only after Word is running).
Copy everything in the new word document (ctrl+a, then ctrl+c).
Paste into Excel, replacing the original column of text. Delete the temporary column with the formula.

I found that none of the methods here worked if the hyperlink did not include http:// as they linked to local locations.
I also wanted to fool-proof the script as the users would not be able to maintain it themselves and I would not be available.
It will only run on cells in a selected range if they contain a dot and no spaces. It will only run for up to 10,000 cells.
Sub HyperAdd()
Dim CellsWithSpaces As String
'Converts each text hyperlink selected into a working hyperlink
Application.ScreenUpdating = False
Dim NotPresent As Integer
NotPresent = 0
For Each xCell In Selection
xCell.Formula = Trim(xCell.Formula)
If xCell.Formula = "" Or InStr(xCell.Formula, ".") = NotPresent Then
'Do nothing if the cell is blank or contains no dots
Else
If InStr(xCell.Formula, " ") <> 0 Then
CellsWithSpaces = CellsWithSpaces & ", " & Replace(xCell.Address, "$", "")
GoTo Nextxcell
End If
If InStr(xCell.Formula, "http") <> 0 Then
Hyperstring = Trim(xCell.Formula)
Else
Hyperstring = "http://" & Trim(xCell.Formula)
End If
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=Hyperstring
End If
i = i + 1
If i = 10000 Then Exit Sub
Nextxcell:
Next xCell
If Not CellsWithSpaces = "" Then
MsgBox ("Please remove spaces from the following cells:" & CellsWithSpaces)
End If
Application.ScreenUpdating = True
End Sub

For me I just copied the entire column which has the URLs in text format into another application (say Evernote), and when they were pasted there they became links, and then I just copied them back into Excel.
The only thing here is you need to make sure the data you copy back lines up with the rest of the columns.

Try this:
=HYPERLINK("mailto:"&A1, A1)
Replace A1 with your text of email address cell.

For anyone landing here with Excel 2016, you can simply highlight the column, then click the Hyperlink tab located on the Home ribbon in the Styles box.
Edit: Unfortunately, this only updates the cell style, not the function.

You can insert the formula =HYPERLINK(<your_cell>,<your_cell>) to the adjacent cell and drag it along all the way to the bottom. This will give you a column with all the links. Now, you can select your original column by clicking on the header, right-click, and select Hide.

If you copy the text contents into a new column and use:
=HYPERLINK("http://"&B10,B10)
on your original column. Then use the $ for the column so it looks like this:
=HYPERLINK("http://"&$B10,$B10)
That's the only way it worked for me on Excel 2010 on Windows 7. You can copy down the formula.

Put the URLs into an HTML table, load the HTML page into a browser, copy the contents of that page, paste into Excel. At this point the URLs are preserved as active links.
Solution was proposed on http://answers.microsoft.com/en-us/mac/forum/macoffice2008-macexcel/how-to-copy-and-paste-to-mac-excel-2008-a-list-of/c5fa2890-acf5-461d-adb5-32480855e11e by (Jim Gordon Mac MVP)[http://answers.microsoft.com/en-us/profile/75a2b744-a259-49bb-8eb1-7db61dae9e78]
I found that it worked.
I had these URLs:
https://twitter.com/keeseter/status/578350771235872768/photo/1
https://instagram.com/p/ys5ASPCDEV/
https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10881854_329617847240910_1814142151_n.jpg
https://twitter.com/ranadotson/status/539485028712189952/photo/1
https://instagram.com/p/0OgdvyxMhW/
https://instagram.com/p/1nynTiiLSb/
I put them into an HTML file (links.html) like this:
<table>
<tr><td>https://twitter.com/keeseter/status/578350771235872768/photo/1</td></tr>
<tr><td>https://instagram.com/p/ys5ASPCDEV/</td></tr>
<tr><td>https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10881854_329617847240910_1814142151_n.jpg</td></tr>
<tr><td>https://twitter.com/ranadotson/status/539485028712189952/photo/1</td></tr>
<tr><td>https://instagram.com/p/0OgdvyxMhW/</td></tr>
</table>
Then I loaded the links.html into my browser, copied, pasted into Excel, and the links were active.

Thank you Cassiopeia for code. I change his code to work with local addresses and made little changes to his conditions. I removed following conditions:
Change http:/ to file:///
Removed all type of white space conditions
Changed 10k cell range condition to 100k
Sub HyperAddForLocalLinks()
Dim CellsWithSpaces As String
'Converts each text hyperlink selected into a working hyperlink
Application.ScreenUpdating = False
Dim NotPresent As Integer
NotPresent = 0
For Each xCell In Selection
xCell.Formula = Trim(xCell.Formula)
If InStr(xCell.Formula, "file:///") <> 0 Then
Hyperstring = Trim(xCell.Formula)
Else
Hyperstring = "file:///" & Trim(xCell.Formula)
End If
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=Hyperstring
i = i + 1
If i = 100000 Then Exit Sub
Nextxcell:
Next xCell
Application.ScreenUpdating = True
End Sub

I had a list of numbers that feed into url's I want hotlinked.
For example I have Column A with question numbers (i.e., 2595692, 135171) and I want to turn these question numbers into hotlinks and to display only the question numbers.
So I built a text-only hyperlink pointing to Column A, and copied it down for all my question numbers:
="=HYPERLINK("&"""http""&"":"""&""&"&"&"""//stackoverflow.com/questions/"&A1&""""&","&A1&")"
Then I copy - paste value this column of text hyperlinks to another column.
You end up with a column of text that looks like the following:
=HYPERLINK("http"&":"&"//stackoverflow.com/questions/2595692",2595692)
Then I selected these pasted items and ran the F2Entry Macro that follows:
Sub F2Enter()
Dim cell As Range
Application.Calculation = xlCalculationManual
For Each cell In Selection
cell.Activate
cell = Trim(cell)
Next cell
Application.Calculation = xlCalculationAutomatic
EndSub
I then deleted the text entry column and Column A.
I ended up with a single column of hotlinked question numbers:
2595692
135171
etc.
Cheers

On Mac, a dead easy way to do it is select your entire spreadsheet in Excel, copy, launch Numbers, paste, then select all, copy, and paste back into Excel.

Easiest way here
Highlight the whole column
click ''insert''
click ''Hyperlink''
click ''place in this document''
click ok
thats all

The simplest way in Excel 2010:
Select the column with the URL text, then select Hyperlink Style from the Home tab.
All URLs in the column are now hyperlinks.
Also double clicking each cell at the end of the URL text and adding a blank or just enter will also produce a hyperlink. Similar to the way you have to create URL links in MS Outlook emails.

There is a very simple way to do this. Create one hyperlink, and then use the Format Painter to copy down the formatting. It will create a hyperlink for every item.

Related

Data imported to Excel as "general", text started with "=", getting "#name?" Is there a way to get it back to text?

On of our offices started their text data with an equals sign, which, when imported into the spreadsheet, gave the #NAME? error.
Now, I know I can change the cell format to text and then click in the formula bar, and excel recognizes the cell as text, but is there a way to do this through VBA?
EXAMPLE:
Cell display value: #NAME?
cell text =-Notice, ABC
Desired OUTPUT: Notice, ABC
now, normally, I'd do something like
sub convert_it()
if left(cells(1,1).value,2) ="=-" then cells(1,1).value = _
right(cells(1,1).value, len(cells(1,1).value) -2)
end sub
but that returns a type mismatch error.
Is there some way I can get the text in the cell without manually clicking?
I can click a few thousand times and then Excel recognizes it as text again, and not as an error, but I'd rather avoid that.
You can do this with VB, or just highlight the whole sheet, hit CTRL-H, type = in the Find and '= in the Replace, then click Replace All. This will make Excel stop thinking that these are formulas.
Instead of using .Value you have to use .Formula, since it's being interpreted as such here:
sub convert_it()
if left(cells(1,1).formula,2) ="=-" then cells(1,1).formula = _
right(cells(1,1).formula, len(cells(1,1).formula) -2)
end sub
Naturally you would place your code within a loop for the column. But I agree that it might be easier to just do a large find/replace.

How do I hide select text in excel (getting weird cells with conditional formatting)

How do hide cells that contain text in excel? These cells I am manually entering numbered data into them. I'd like them to be invisible when containing SetNumber but when I enter data manually, the data is visible.
I have seen a number of vba solutions and this solution which did not work. My question is how do I hide columns A, B and C which all contain SetNumber?
I have used conditional formatting but for some reason the output appears very un-natural. Is there a simple alternative?
To complete my comment above, you can do (in VBA):
Dim celltxt As String
celltxt = ActiveSheet.Range("A1").Text
If InStr(1, celltxt, "SetNumber") Then
Range("A:A").EntireColumn.Hidden = True
EndIf
To hide Column A based upon the contents of cell A1. You should be able to modify this to suit your needs.

Efficiently copy text from Excel to Word, hyperlink if applicable

What I'm trying to do
I'm trying to copy contents of different Excel cells into their respective Word bookmarks. Then this filled-in Word document gets pasted into an Outlook email. If the cell has a URL in it, I want it to be a clickable hyperlink in the email.
The problem
If the cell's value was a URL, then while it was un-hyperlinked before sending the email, it appeared hyperlinked (for some people) when the email was received. However, others users saw what looked like a clickable link (blue and underlined), but were unable to click because it wasn't actually hyperlinked. My guess is that certain mail programs recognize the URL and automatically hyperlink it while others do not.
What I've tried
I figured the solution was to make sure the URL was hyperlinked before sending. I tried a few forms of .PasteSpecial and .PasteAndFormat with the URL already hyperlinked in Excel. I got close, but either got an unwanted carriage return or no hyperlink. My latest try is a 2-line hack:
'put the cell contents in (sans formatting)
BKMRange.Text = ActiveCell.Value
'If it looks like a hyperlink, then hyperlink it
If UCase(Left(ActiveCell.Value, 4)) = "HTTP" Or UCase(Left(ActiveCell.Value, 4)) = "WWW." Then TempEmailDoc.Hyperlinks.Add BKMRange, ActiveCell.Value
The problem with this is that if the cell is more than just a URL (e.g. "This is your URL: www.google.com"), the URL won't get hyperlinked, since the first 4 characters are not "HTTP" or "WWW.". I could do a more robust search for "HTTP" or "WWW.", but then the code becomes much more complicated. There must be a more efficient way.
My question
How can I efficiently copy cell contents, but preserve hyperlinks if the cell contains them?
Thanks!
You can use the cell's Hyperlinks collection to learn whther the cell contains a hyperlink:
Sub test()
Dim i
i = Selection.Hyperlinks.Count
If (i > 0) Then MsgBox Selection.Hyperlinks(1).Address
End Sub
Now that you know a cell is (contains) a hyperlink, you can insert it as a hyperlink in Outlook. I assume you work in Outlook VBA and open the worksheets in Outlook VBA.
Note that when you enter a proper URL in Excel it will turn it automaticlly into a hyperlink.

VBA code to clear FORMATTING and leave plain text data in a chosen column in Excel

I need to create a button to add to Excel (2010 currently) that will strip all the formatting in that column and just leave plain text. Our current solution is to copy the data into Notepad to strip out the formatting and then copy it back in from Notepad. This works, but is inelegant and would be far easier if I could just create a button to do this within Excel itself. I've seen a few solutions posted but none of them seem to deal with a randomly selected column. Help!
The Range.ClearFormats method seems appropriate here.
With Worksheets("Sheet1")
.Columns(1).ClearFormats 'clear formatting from column A
End With
'for a manually selected group of cells
Selection.ClearFormats 'clear formatting from the cells currently selected
fwiw, the Clear Formats command is available on the ribbon through Home ► Editing ► Clear ► Clear Formats (Alt+H+E+F). You could easily add that command to the QAT rather than create a macro that largely duplicates the command and assign it to a custom button.
Excel already has a button on the Home tab:
Just select the entire column and click Clear Formats
Just to add to Jeeped's answer:
Using this code you'll clear the whole columns formatting (select a random cell, run this code and the whole columns formatting has been cleared)
Sub ClearColumn()
i = ActiveCell.Column
ActiveSheet.Columns(i).ClearFormats
End Sub

Major formatting issue in Excel - VLOOKUP

I need help with a formatting issue in Excel, which is interfering with the VLOOKUP function in my Excel sheet.
I have two sheets with more than 20,000 column values as lookup, and the same number of values for reference. All the values in both cells are weirdly formatted, some with green triangles at the upper left corner of cells, some are text, etc.
Is there a way in Excel using a macro/VBA to remove or make all formatting similar in both sheets? The reason for VBA is because the person who is going to work with this file needs everything automated and is not familiar with Excel at all. I already have the VLOOKUP function in the cells, I just need to work with the formatting.
Well, I fight with partial lookups this way:
In the items array, I create new empty FIRST column and then place formula
="+"&B2
This will take the content of Cell B2 and add + in the front of it.
When I do vlookup, I add "+" to searcheable value
=VLOOKUP("+"&A6,A:O,2,FALSE)
Therefore, instead of comparing for example Strings and numbers, I compare Strings, by adding "+" in the front.
Another technique, is to kill all formatting:
Select whole column, click DATA-TEXT TO COLUMNS-DELIMITED and then DESELECT ALL DELIMITERS. Click Finish. This will clear your formatting.
===========================================================================
This is the VBA solution you asked for:
Call it from Excel
=GetLookup(G2,A:C)
Here is VBA:
Function GetLookup(LOOKFOR As String, RANGEARRAY As Range) As String
GetLookup = Application.WorksheetFunction.VLookup("+" & LOOKFOR, RANGEARRAY, 3, False)
End Function
Good luck!
I'm assuming the data type in all of the cells is the same, or you want it to all be the same. The following steps will make the cells a uniform type:
Save your workbook, in case this does not do as you require
Select all cells you wish to be of the same cell type
Press Ctrl+1, on the "Number" tab, select the type you wish these cells to take. Press OK.
Open the VBA editor using Alt+F11
Open the immediate window with Ctrl+G
Type the following: for each cell in selection : cell.formula = cell.value : next cell
Press enter (you may have to wait a few seconds).
If you take this action with the same data type (e.g. choose "Text" for both ranges in step 3) on both your ranges you should be "comparing apples with apples" and your VLOOKUP should function as required.
Hope this helps.
Edit: formatting, clarification