I need some help with this Sub when the text condition isn't met inside the For loop. The Sub works perfectly if each cell in the column meets the condition and it also works on a column until the condition isn't met, then stops.
Based on what I have read, it needs something like IF, THEN, ELSE, but when I try that inside the For loop I keep getting errors.
Ideally, I'd like it to move on to the next cell if it can't find ">" in the cell, until it reaches the last row with data in the cell.
In this example the first column completed without stopping, the second column stopped after the first cell and the third column won't work at all.
Thanks in advance,
Don
Based on what I have read, it needs something like IF, THEN, ELSE, but when I try that inside the For loop I keep getting errors.
Ideally, I'd like it to move on to the next cell if it can't find ">" in the cell, until it reaches the last row with data in the cell.
In this example the first column completed without stopping, the second column stopped after the first cell and the third column won't work at all.
PPM Link | Impact Assessment Link | ROM Link |
PPM Link | Impact Assessment Link | #Value! |
PPM Link | #Value! | #Value! |
PPM Link | <a href="http://blah/blah/Lists/IA/DispForm.aspx?ID=261">http://blah/blah/Lists/IA/DispForm.aspx?ID=261</a> | <a href="http://blah/blah/blah/small/50463%20XYZ%20%20Annual%20AntiFraud%20Verification%20Repo/1.%20Initiate/XYZ%2050463%20ROM%20-%20Annual%20foo%20Verification%20Report.xlsm">ROM Link</a> |
PPM Link | #Value! | #Value! |
PPM Link | #Value! | #Value! |
PPM Link | <a href="http://blah/blah/Lists/IA/DispForm.aspx?ID=581">http://blah/blah/Lists/IA/DispForm.aspx?ID=581</a> | <a href="http://blah/blah/blah/ABC/99999%20ABC%20%20eLTCAS%20foo%20Approval%20Letter%20Update/1.%20Initiate/ABC%2051110%20ROM%20-%20efoo%20Claim%20Approval%20Letter%20Update.xlsm">ROM Link</a> |
PPM Link | <a href="http://blah/blah/Lists/IA/DispForm.aspx?ID=261">http://blah/blah/Lists/IA/DispForm.aspx?ID=261</a> | <a href="http://blah/blah/blah/small/77777%20BBB%20%20Annual%20foo%20Verification%20Repo/1.%20Initiate/BBB%2050463%20ROM%20-%20Annual%20foo%20Verification%20Report.xlsm">ROM Link</a> |
PPM Link | <a href="http://blah/blah/Lists/IA/DispForm.aspx?ID=562">http://blah/blah/Lists/IA/DispForm.aspx?ID=562</a> | <a href="http://blah/blah/blah/DDD/51165%20DDD%20%20Active%20foo%20Listing%20RERUN%20%20was%20PP/1.%20Initiate/51165%20DDD%20Active%20foo%20Listing%20Rerun%20ROM%20(formerly%2050814).xlsm">51165 ROM </a> |
PPM Link | #Value! | #Value! |
PPM Link | #Value! | <a href="http://blah/blah/_layouts/15/listform.aspx?PageType=6&ListId=%7B5E40835D%2D8C93%2D40C4%2DB6E9%2D7DCF62BCE046%7D&ID=403">ROM Link</a> |
VBA Code:
Option Explicit
Sub AddHyperlinksfrom_hRef_CellText()
'JBeaucaire (11/9/2009)
Dim LR As Long, i As Long, Txt As String, UserCol As String
'Create InputBox, and Assign value returned by InputBox function to variable UserCol
UserCol = InputBox(Prompt:="Please enter a Column (A-Z)", title:="Create Excel VBA InputBox", Default:="Column value here")
LR = Range(UserCol & Rows.Count).End(xlUp).Row
'Change Number value (2) to be the start row
For i = 2 To LR
Txt = Mid(Cells(i, UserCol), 10, InStr(Cells(i, UserCol), ">") - 11)
ActiveSheet.Hyperlinks.Add _
Anchor:=Cells(i, UserCol), _
Address:=Txt, _
ScreenTip:=Txt, _
TextToDisplay:=Cells(1, UserCol).Text
'TextToDisplay:=Cells(i, "A").Text
Next i
End Sub
Thanks in advance,
Don