Solved

Prompt user to enter a column letter using VBA

Posted on 2016-09-26
2
74 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

627 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