entering complex formula using VBA

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
682
Office Version
  1. 365
Hi All

I've been on this for hours and there must be an easier way to do this but I'd like to persevere with the formula route if possible

I'm attempting to enter a formula via vba to add a hyper link, I've been going around in circles for what seems like a lifetime (probably about 2 hours) and cant seem to get it right.

A couple of question

is it possible to do this??
if it is, any ideas where I'm going wrong??

Any help would be appreciated

Kind regards

Paul


Code:
Sub create_new_sheet()


Sheet1.Unprotect Password:="password1"


Sheet1.Range("K3") = Sheet2.Range("X7").Value


 Dim strName As String
    Dim wk As Worksheet
    
    strName = Sheet2.Range("X7")
    On Error Resume Next
    Set wk = Worksheets(strName)
    On Error GoTo 0
    If wk Is Nothing Then
        Sheet1.Visible = True
        Sheet1.Copy After:=Worksheets(Worksheets.Count)
NewPageName = Sheet2.Range("X7")
ActiveWindow.ActiveSheet.Name = NewPageName
Sheet16.Visible = False


          Else: MsgBox "Project Already Exists", vbExclamation, "Project Exists"
        Exit Sub
    End If
    
'add hyperlink
Sheet2.Range("X7").Copy
With Sheet17
.Range("B1").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Transpose:=True


[COLOR=#ff0000].Range("B1").Cells(Rows.Count, "B").End(xlUp).Offset(0, 1).Formula = "=HYPERLINK(CELL(""LEFT(CELL(""filename""),FIND(""]"",CELL(""filename""),1))"")&""-'" & "C" & ActiveCell.Row & "'!A1"",""My Name"")"[/COLOR]
End With


'info_to_register
           
End Sub
 
Hi

that exactly what I'm after, sorry it took me so long to get there

regards

Paul
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
sorry I still cant get it to work

I'm trying the below

.Range("B1").Cells(Rows.Count, "B").End(xlUp).Offset(0, 1).Formula = "=HYPERLINK(""#" & Sheet2.Range("X7") & "!A1"",""Test Name"")"

It's not throwing any errors and putting the link in the correct place, Sheet2.Range("X7") value is being displayed in the link if you hover over it
 
Upvote 0
Hi
thanks for sticking with me, I've finally got it working (y)

Here you go

.Range("B1").Cells(Rows.Count, "B").End(xlUp).Offset(0, 1).Formula = "=HYPERLINK(""#'" & Sheet2.Range("X7") & "'!A1"",""Test Name"")"

it just needed the ' at the beginning and end of the sheet name

Phew!!!!

thanks for all the support, I was being led astray by looking at the full link you see when you enter the hyper link manually

thanks again for the assistance

cheers

Paul
 
Upvote 0
No, it means "in this document."

You're welcome.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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