Solved

Prompt user to enter a column letter using VBA

Posted on 2016-09-26
2
35 Views
Last Modified: 2016-09-26
Dear Experts:

Below Code converts Path Entries in Column 'B' to Hyperlinks. The macro works just great.

Could somebody help me to tweak this code in the following way:

The path entries could be in any column and I do not want to hard code the macro every time the column letter changes (the macro is activated also by other people)

An Input Box is to prompt the user to enter the column letter and then the macro runs.

Only single column letters are allowed, i.e. A till Z. Any other caracter that is entered (numbers, alphanumeric entries, space(s) etc) will trigger an error.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub Convert_Path_To_Hyperlinks()

Dim r As Range
Dim MyValue As String

On Error Resume Next

   For Each r In Range("B2", Range("B2").End(xlDown))
     
   If r.Value <> "" Then

         MyValue = r.Value

            Range(r.Address).Select

               ActiveSheet.Hyperlinks.Add Anchor:=Excel.Selection, Address:=MyValue, TextToDisplay:=MyValue

     End If

   Next r

    Range("a1").Select

End Sub

Open in new window

0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41816448
Hi,

pls try

Sub Convert_Path_To_Hyperlinks()

Dim r As Range
Dim MyValue As String

strCol = Application.InputBox("Enter Column", "Column", , , , , , 2)
If Not strCol Like "[A-Za-z]" Then
    MsgBox "Wrong input"
    Exit Sub
End If

On Error Resume Next

   For Each r In Range(Range(strCol & "2"), Range(strCol & "2").End(xlDown))
     
   If r.Value <> "" Then

         MyValue = r.Value

            Range(r.Address).Select

               ActiveSheet.Hyperlinks.Add Anchor:=Excel.Selection, Address:=MyValue, TextToDisplay:=MyValue

     End If

   Next r

    Range("a1").Select

End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 41816516
Great this did the trick. Thank you very much for your great help.

Regards, Andreas
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now