Wednesday, September 17, 2008

Excel Convert Multiple Cells to URLs

This will convert the selected cell range to a URL.  It assumes that the selected cells are vaild URLs but will skip empty cells.  

Sub Convert2URL()
    For Each cell In Selection
        If cell.Value <> "" Then
            If Left(cell.Value, 7) = "http://" Then
                URL = cell.Value
            Else
                URL = "http://" + cell.Value
            End If
            ActiveSheet.Hyperlinks.Add Anchor:=cell, _
              Address:=URL, TextToDisplay:=cell.Value
        End If
    Next cell
End Sub

Now lets say you have a list of order numbers and you want to click a link in Excel and go right to your order management screen you could do:

Sub Convert2URL()
    For Each cell In Selection
        If cell.Value <> "" Then
            If Left(cell.Value, 44) = "http://myordermanager.net/ordermanager.php?" Then
                URL = cell.Value
            Else
                URL = "http://myordermanager.net/ordermanager.php?" + cell.Value
            End If
            ActiveSheet.Hyperlinks.Add Anchor:=cell, _
              Address:=URL, TextToDisplay:=cell.Value
        End If
    Next cell
End Sub

Yup, its neat-o and works like a charm!

Excel Time Difference Formula

Yeah, I know this is all round the great interweb but I don't care.  I want to post it here too so I KNOW where it is.  This blog is not just to help someone else after I found a solution.  I often come back here myself to find solutions I have used in the past.


=IF(D2>H2,B2+1-D2,H2-D2)

D2 = Start Time
H2 = End Time

Yeah, it look complicated but it works wonderfully.  It doesn't take into account dates, so it only works from one day to the next if going over night.