Column A contains hyperlinks underneath other text.
How can I pull the hyperlinks into column B?
And then, what if I also wanted to trash the underlying hyperlinks in Column A?
:dunno
Printable View
Column A contains hyperlinks underneath other text.
How can I pull the hyperlinks into column B?
And then, what if I also wanted to trash the underlying hyperlinks in Column A?
:dunno
maybe something like this??...
Code:Sub transfer()
Dim rng As Range
Set rng = Range("A1:A10")
rng.Copy
Range("B1:B10").PasteSpecial (xlPasteAll)
With rng
.Hyperlinks.Delete
End With
End Sub
change ranges to suit. (if i understood correctly).
LOL!
I'm hoping for this to be a future KB contribution. I can't have hard-coded cells! Hee hee. Sorry. I shoulda said so, Zack. :)
Let's suppose that I want all cells from A2 and down the used range of column A.
:) ok, how about this:
Code:Sub transfer()
Dim rng As Range
Set rng = Range("A2", Range("A2").End(xlDown))
rng.Copy
rng.Offset(0, 1).PasteSpecial (xlPasteAll)
With rng
.Hyperlinks.Delete
End With
Application.CutCopyMode = False
End Sub
better?
or will there possibly be non-contiguous ranges wanted with this? if so, how about:
this better? or am i shootin blanks here?Code:Sub transfer()
Dim rng As Range
Set rng = Range("A2", Range("A65536").End(xlUp))
rng.Copy
rng.Offset(0, 1).PasteSpecial (xlPasteAll)
With rng
.Hyperlinks.Delete
End With
Application.CutCopyMode = False
End Sub
I thought you had kids? :p
Okay...bad, bad me.
WORKED GREAT!!
damn straight... :*)Quote:
Originally Posted by Dreamboat
How about this for being more generic?
The benefit of this method is that neither range is hard-coded.
Code:Public Sub example()
'This subroutine acts as an example of how to use the "target" subroutine
Dim oRange As Range
Dim oTarget As Range
Set oRange = Range("A2", Range("A65536").End(xlUp))
Set oTarget = oRange.Offset(0, 1)
transfer oRange, oTarget
End Sub
Private Sub transfer(ByRef rng As Range, ByRef Target As Range)
'This is the actual solution to the post
rng.Copy
Target.PasteSpecial (xlPasteAll)
With rng
.Hyperlinks.Delete
End With
Application.CutCopyMode = False
End Sub
I think the 'problem' needs a bit more definition. Originally it was column A to column B; now it's variable (User-supplied) ranges - big difference :) .
Is this to run from the User Interface - in other words is the User going to specify the source range - by selection, let's say, before clicking a button. And if so, how is the user going to specify the target, or should it always be the column to the right - or a new column? What if the source range is multicolumn - should new columns (if wanted) be added as a block, or interleaved? If a single column goes to the column on the right, should, say, a single row selection go to the row BELOW?
What should happen to non-hyperlink data in the source range? What should happen to existing data in a (User-selected) target range?
I do think it's reasonable to insist on a single contiguous range.
Ignoring selections for a minute, one point about all the code offered so far is that it doesn't separate out the hyperlinks from the friendly names which seems to be what was asked for. I think this requires spinning through the Hyperlinks Collection.
Well, let's define it then.
What would be the best if someone asked the question the way I did? What code is going to be the easiest to use and implement for the average person (who usually knows NO VBA).
Code:Public Sub main()
Dim oRange As Range
'The rest of this code will be green.
'and formatting not preserved.
'(most notably when you edit the post)
MsgBox "hi"
Set oRange = ActiveSheet.Range("A1")
End Sub
Edit by mark007: hmm, I saw a post like this before and when I went to edit it it looked fine then when I saved changes it looked fine. I'm not sure what the issue is. Does it happen everytime you post?
EDIT:: OS is Win2K. Yes, when I editted the post previously it jacked up the spacing, but now it seems to work.
BTW, for clarity it's probably better to reply to a post like this rather than to edit it.
In a stab in the dark - what OS/browser are you using?
If you edit it again will it revert to all green?
:)
I always try to target the KISS-concept:Quote:
What code is going to be the easiest to use and implement for the average person.
Keep it simple, stupid (for the end-users)
An add-in that is automatically activated upon installation
where the function is available via a toolbar button and/or menu-option and
where the end-users select the source-range (before hitting the button)
and then via a small inputbox select the first target-cell.
Based on this approach we can start to write the code as we have located the functionality and a userfriendly interface.
Do we have green light?
Dennis
Dennis,
I agree 100% - if it ain't simple to use it won't get used.
I'll go with your definition. And ..
.. overwrite cells in target range
.. copy non-hyperlinks in range unchanged?
.. disallow overlapping ranges?
Anybody else?
I just want to say...I have never seen so many experts working together, and really discussing the issues. This is too cool. The neat thing is that the outcome is as good as it can be, and our KB will be so *&^%$## sweet!!!
Tony,
I?m with You - :thumb
Kind regards
Dennis
ditto - DennisQuote:
Originally Posted by Dennis W
I guess I'm following the UI discussion here. I editted firefytr's code with a suggestion to make the subroutine generic, I was not trying to address the initial problem:
Code:Private Sub transfer(ByRef rng As Range, ByRef Target As Range)
'This is the actual solution to the post
rng.Copy
Target.PasteSpecial (xlPasteAll)
With rng
.Hyperlinks.Delete
End With
Application.CutCopyMode = False
End Sub
You can copy this code in anywhere and call it from a main subroutine. The GUI doesn't matter as much as the code interface. The subroutine as I posted becomes an encapsulated, standalone routine. You pass two ranges and the routine does the rest.
I provided an example subroutine as to how you could use it. I don't think it really matters howthe GUI is set up since that just creates more overhead on the forum. i.e. it doesn't matter if the OP wants to create an add-in or a userform or use a intputbox to get the ranges. If the OP needs that help, then they will ask.
Or am I missing something here? :dunno
I saw this question posted elsewhere, and wished we had it as a contribution at www.vbaexpress.com/kb, which is the primary purpose of this site, and will be implemented as soon as we have a submission form.Quote:
more overhead on the forum
I wanted this thread to result in a contribution by whoever...
All we need to do is handle, say, any range in col A gets dumped over to the adjacent cells in B. Yes, it'd be nice if it can be in ANY col and get dumped over to the next column to the right.
User interface is unnecessary at this point since it's not an addin or anything like that. However, is this something we should add to the World Tag Excel Addin?
I can't test the code because I can't run it. If we're going to add it to the KB, then we need those instructions. I'm sure YOU all know how, but me don't!
Yes, Mark, the UI and the functionality are different beasts - it was Anne's second post that I thought brought the UI into scope, and there is probably a bigger issue here to do with run instructions.
If I were an ignorant user (some say I am, of course :) ) how could I take a KB solution and use it? Posting detailed instructions with every piece of code is way over the top; should there be some generic instructions somewhere so that, in an individual case it's sufficient to say something like - paste this code into a standard code module (or ThisWorkbook, or wherever), close the VBA, etc. - which can then be referred to?
Anyway, in this instance, none of the code posted so far has separated out the underlying hyperlinks, so here's some code which does ..
This could be used with something like ..Code:Private Sub transfer(ByRef rng As Range, ByRef Target As Range)
Dim h As Hyperlink
rng.Copy
Target.PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
With rng
.Hyperlinks.Delete
End With
For Each h In Target.Hyperlinks
h.TextToDisplay = h.Address & IIf(h.SubAddress = "", "", IIf(h.Address = "", "", " - ") & h.SubAddress)
Next
End Sub
Code:Sub TestIt()
' Get SourecRange from User
' Get TargetRange from User
transfer SourceRange, TargetRange
End Sub
where Getting the ranges from the User are (probably) other KB code routines.
Well, well, well - I didn't tag my second piece of 'code' but the system identified it as VBA - very clever!