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?
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?
~Anne Troy
maybe something like this??...
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).
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
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.
Last edited by Anne Troy; 05-25-2004 at 04:08 PM.
~Anne Troy
ok, how about this:
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?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
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
I thought you had kids?
Okay...bad, bad me.
WORKED GREAT!!
~Anne Troy
damn straight...Originally Posted by Dreamboat
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
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.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!
~Anne Troy
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 ..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
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.
Last edited by Aussiebear; 04-30-2023 at 02:09 AM.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Well, well, well - I didn't tag my second piece of 'code' but the system identified it as VBA - very clever!
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Not exactly...Originally Posted by TonyJollans
A little birdie happened to see it...
~Anne Troy
Hi all :hi
Unlike other boards I like to see that we also include error-handling in the provided solutions, especially when they are supposed to be used by less skilled user.
Therefore I made the following add-ons:
Kind regards,Option Explicit Sub Do_It() Dim rnSource As Range, rnStart As Range, rnTarget as Range If ActiveSheet.ProtectContents = False Then If TypeName(Selection) = "Range" Then With Selection If .Columns.Count <> 1 Then MsgBox "Please make sure that the selection only contains one column.", vbInformation GoTo ExitHere ElseIf .Areas.Count <> 1 Then MsgBox "Please make sure that the selection only covers one area.", vbInformation GoTo ExitHere Else Set rnSource = Selection End If End With Else MsgBox "You need to select a range before executing this procedure.", vbExclamation GoTo ExitHere End If Else MsgBox "You need to unprotect the worksheet before executing this procedure.", vbExclamation GoTo ExitHere End If On Error Resume Next Set rnStart = Application.InputBox( _ Prompt:="Please select the first cell in the target range:", _ Title:="Select targetrange", _ Type:=8) On Error GoTo 0 If rnStart Is Nothing Then GoTo ExitHere Else Set rnTarget = rnStart.Resize(rnSource.Rows.Count, 1) Transfer rnSource, rnTarget End If ExitHere: Exit Sub End Sub Private Sub Transfer(ByRef rng As Range, ByRef Target As Range) Application.ScreenUpdating = False rng.Copy Target.PasteSpecial (xlPasteAll) With rng .Hyperlinks.Delete End With With Application .CutCopyMode = False .ScreenUpdating = True End With End Sub
Dennis
Last edited by XL-Dennis; 05-27-2004 at 04:06 AM.
Huh? Are you referring to the bit where Anne says she doesn't want the range hard-coded?Originally Posted by TonyJollans
I guess I agree with the last two comments from Tony and Dennis about environment and error trapping, but really, it all seems like overkill for a relatively simple post. Perhaps an example of these techniques in the KB would be easier to simply refer to than to answer every question with 30 lines of code.
I like the idea of always having full error handling, but it's going to put a load on the approvers.
BTW, you need rnTarget As Range
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Tony,
Thanks for the heads up - I added it in the original post
Yes, I agree but I believe it should only be necessary for the KB-articles.
Kind regards,
Dennis
In my book a procedure should never make incidental changes to the environment. I know this is not always possible in VBA, but with ScreenUpdating, I think your example should have ..
Without this, the caller may have set it False only to find it True after calling a sub-routine which he wouldn't want.Private Sub Transfer(ByRef rng As Range, ByRef Target As Range) Dim CallerScreenUpdating as boolean CallerScreenUpdating = Application.ScreenUpdating Application.ScreenUpdating = False ' rest of code Application.ScreenUpdating = CallerScreenUpdating End Sub
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
G8 -
Kind regards,
Dennis
This code, intended for the KB, would be utilitarian: once and done, most likely.
It would be cool if the person didn't have to choose the range, but merely only needed to ensure that wherever their hyperlinks reside, then the cell to the right is blank and can be populated with the hyperlinks.
I don't think we need to get into a big deal with a typical KB entry like this.
However! Were we to implement this feature into the addin...that's a different story!
~Anne Troy
Yupp, but I like to see where we stand when it comes to some aspects for the KB-articles. A general write-up about error-handling is great but as I said I like to see some stuff different here.it all seems like overkill for a relatively simple post
So let the comments come about it
Kind regards,
Dennis
But not here, Den. Can we take this discussion where it belongs?
http://www.vbaexpress.com/forum/showthread.php?t=66
~Anne Troy
Hi Dreamboat,
here another approach. If I read the question correctly then you want to have the hyperlink address in column B. Hereby I asume that the cell contains a value which is shown like "test". Underlying there is a link towards http://www.test.com. This last value you want to see in column B. IN this case you might think about using a macro like:
Sub HyperlinkAddr() Application.ScreenUpdating = False rowsA = Cells(Rows.Count, 1).End(xlUp).row For i = 1 To rowsA If Cells(i, 1).Hyperlinks.Count > 0 Then Cells(i, 1).Offset(0, 1).value = Cells(i, 1).Hyperlinks(1).Address End If Next i Application.ScreenUpdating = True End Sub
I hope this is what you needed.
regards,
Jeroen