Cannot keep leading zeros in hyperlink address

MarkMacka

New Member
Joined
Jan 3, 2017
Messages
6
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


 

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,834
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?
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
4,734
Office Version
2013
Platform
Windows
Mark,

Try....

Rich (BB code):
S.Hyperlinks.Add anchor:=Selection, Address:="R:\Construction\PSI-1\PS\QS\ IR Requests\IR" & Format(v + 1, "0000")
 

MarkMacka

New Member
Joined
Jan 3, 2017
Messages
6
Cheers for that Snakehips. This has been giving me trouble for weeks. That seems to be working beautifully. Much appreciated
 

Forum statistics

Threads
1,082,346
Messages
5,364,822
Members
400,814
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top