Подадрес гиперссылки должен быть на ячейке на листе, как «Имя листа»! A1.
Option Explicit
Private Sub NewWellButton_Click()
Dim wb As Workbook, ws As Worksheet, wsNew As Worksheet, sht As Worksheet
Dim sWellName As String, lastCell As Range, bExists As Boolean, s As String
Set wb = ActiveWorkbook
Set ws = wb.Sheets(1)
sWellName = Application.InputBox("Enter the new well name", Title:="New Well")
If Len(sWellName) = 0 Then
MsgBox "Well Name blank", vbExclamation
Exit Sub
Else
For Each sht In wb.Sheets
If sht.Name = sWellName Then bExists = True
Next
End If
If bExists = False Then
s = "Sheet [" & sWellName & "] does not exist, do you want to create it ?"
If vbYes = MsgBox(s, vbYesNo, "Not Found") Then
Set wsNew = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count))
wsNew.Name = sWellName
ws.Select
End If
End If
' copy
Set lastCell = ws.Cells(Rows.Count, 1).End(xlUp)
lastCell.EntireRow.Copy
' paste below
Set lastCell = lastCell.Offset(1, 0)
lastCell.PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
' add link
With lastCell
.Value = UCase(sWellName)
.Hyperlinks.Add Anchor:=lastCell, Address:="", SubAddress:="'" & sWellName & "'!A1"
End With
End Sub