Macro to Hyperlink value in column A based on directory in column E and file name in column D

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
929
Office Version
  1. 365
Platform
  1. Windows
Hi, I was hoping someone could help me with a macro that could hyperlink every cell in column A to the directory/file name in column D and F. I have a list of hundreds of employees and am looking for a quick way to link to their folders without doing it manually.

Thank you very much to anyone that can help!

Cell Formulas
RangeFormula
D2:D13D2=B2&", "&C2
E2:E13E2="\\198.100.2.77\mydata\Employee Files\"&LEFT(B2,1)&"\"
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

I believe this is what you have requested....

VBA Code:
Sub hyperl1nk()

Dim i, lastrow As Long

With ActiveSheet
lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
End With

For i = 2 To lastrow
DirStr = Range("E" & i).Value & Range("D" & i).Value
ActiveSheet.Hyperlinks.Add Range("A" & i), DirStr
ActiveSheet.Range("I" & i).Value = DirStr

Next i

End Sub
 
Upvote 0
Solution
Hi,

I believe this is what you have requested....

VBA Code:
Sub hyperl1nk()

Dim i, lastrow As Long

With ActiveSheet
lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
End With

For i = 2 To lastrow
DirStr = Range("E" & i).Value & Range("D" & i).Value
ActiveSheet.Hyperlinks.Add Range("A" & i), DirStr
ActiveSheet.Range("I" & i).Value = DirStr

Next i

End Sub
This worked but it put data in column "I" (combined file name with directory)
If I changed how I have the sheet set up could we avoid this? (see below) I do not want to add any additional columns.

Thank you so much for your help!

Cell Formulas
RangeFormula
D2:D13D2=B2&", "&C2
E2:E13E2="\\198.100.2.77\mydata\Employee Files\"&LEFT(B2,1)&"\"&B2&", "&C2


OR

Cell Formulas
RangeFormula
D2:D13D2="\\198.100.2.77\mydata\Employee Files\"&LEFT(B2,1)&"\"&B2&", "&C2
 
Upvote 0
Hi,
It wasn’t a helper column, you can remove this line:

VBA Code:
ActiveSheet.Range("I" & i).Value = DirStr
to stop it.
I thought the yellow cell was a header, so I put data there (I instead of J though!)

You didn’t need to remodel the sheet
 
Upvote 0
Hi,
It wasn’t a helper column, you can remove this line:

VBA Code:
ActiveSheet.Range("I" & i).Value = DirStr
to stop it.
I thought the yellow cell was a header, so I put data there (I instead of J though!)

You didn’t need to remodel the sheet

Perfect! Thank you very much! :giggle:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top