Cannot keep leading zeros in hyperlink address

MarkMacka

New Member
Joined
Jan 3, 2017
Messages
9
This is a code that creates a value in a cell based on the previous line number, it then hyperlinks this cell to the associated file folder for that Inspection number

Range "G" is the cell to receive the hyperlink.

=SUM(R[-1]C[-6]+1)" Takes the previous line number in from one row above column A, and adds 1.

(example)
Row A = 13 but is custom number formatted ("IR"0000)to show IR0013
Row G is also custom number formatted so it will now show IR0014 next line down when macro runs.

When the hyperlink is created using this cell value it deletes the leading zeros so the end address shows "R:\ Construction\PSI-1\PS\QS\ IR Requests \IR14"

(The target files for link are named containing leading zeros)

It doesn’t seem to matter how I format or name the recipient cell in range G, it always drops the leading zeros in the hyperlink address.

To bypass this I have added two zeros after "IR" in the S.Hyperlinks.Add" string which works but needs to be changed manually as numbers grow from tens to hundreds etc.

Any help on this would be greatly apreciated as i have run out of ideas.

 


Range("G" & (ActiveCell.Row)).Select

ActiveCell = "=SUM(R[-1]C[-6]+1)"



Dim S As Range

For Each S In Intersect(ActiveCell(r1c1), ActiveSheet.UsedRange)

v = S.Value

If v <> "" Then

S.Hyperlinks.Add anchor:=Selection, Address:="R:\Construction\PSI-1\PS\QS\ IR Requests\IR
00" & v + 1

End If

Next S


 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
SUM(R[-1]C[-6]+1) - The SUM here is unnecessary. You could write just R[-1]C[-6]+1.
Could you post your workbook (with sensitive data removed) to some cloud storage?
 
Upvote 0
Mark,

Try....

Rich (BB code):
S.Hyperlinks.Add anchor:=Selection, Address:="R:\Construction\PSI-1\PS\QS\ IR Requests\IR" & Format(v + 1, "0000")
 
Upvote 0
Cheers for that Snakehips. This has been giving me trouble for weeks. That seems to be working beautifully. Much appreciated
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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